James John – Software Engineer

Interprete and Parse Meta Robot Values Using PHP

Hey reader, you really need to see this PHP meta robots parser?

So damn easy, now lets get our hands dirty ;). Am writing a function that interprets the meta robots which receives arguments of strings (e.g noindex,nofollow), you can grab this with the get_meta_tags() function then let me start the function to parse this.

In this function I return 4 values which are:

Now starting the function, firstly lets check if the argument has a value, if empty then return 200

Else lets do our stuff by exploding argument value into simple arrays but wait! Do you know some people put spaces after the comma in their meta robots and some don’t? (e.g NOINDEX,NOFOLLOW or NOINDEX, NOFOLLOW). Now let’s handle this to avoid logical error, we will parse the array and trim() each array value then gather them back to array 🙂

Now lets do the comparison by checking if value is in array:

Now the full code:

James John

Software Engineer