Get An Array Of Meta Tags Php
Solution 1:
get_meta_tags
returns an array, use print_r()
to see it's structure, and loop through them to print them however you want:
foreach($tagsas$tag){
echo$tag."\n";
}
Edit: And you don't need to stick the restult of get_meta_tags
in another array, then you just have an extra one for no reason.
explode(',',$meta['tags']);
Solution 2:
If your question is now how would I get comma-separated values as different tags?, you could do something like this:
<meta name="tag" content="plant, leaf, waterdroplet, water" />
$tags = get_meta_tags('yourfile.html');
$tags = array_map('trim', explode(',', $tags['tag']));
This will explode the words into an array, and remove any whitespace, you can then loop over this for outputting/whatever else:
example
foreach($tagsas$k => $v) {
echo$k . ': ' . $v . '<br />' . "\n";
}
Would output:
0: plant1: leaf2: waterdroplet3: water
Solution 3:
You are getting the tags correctly, but not displaying them correctly.
You can't use echo
on an array.
You can use var_dump to see the whole array that you have - which should show you how to access it in your code.
Solution 4:
You are making a mistake in setting the tags
<metaname="tag"content="xx" /><metaname="tag"content="yz" />
When you execute get_meta_tags()
on that, it will only show you the last value (in that case: yz
)
So you need to put different names on the tags
eg
<metaname="tag1"content="yz" /><metaname="tag2"content="yz" />
Solution 5:
The names must be unique. See the documentation of this function:
If two meta tags have the same name, only the lastoneis returned.
So you can only have on meta-tag with name="tag", so better try a comma separated value for that.
Post a Comment for "Get An Array Of Meta Tags Php"