I’m using get_meta_tags() in a script and on certain URLs it fails out with (as an example)…
Warning: get_meta_tags(http://www.kodak.com/) [function.get-meta-tags]: failed to open stream: Redirection limit reached…
Is it possible to just skip over any result that throws an error? Or should I just use @get_meta_tags() instead?
function getMeta()
{
$tags = get_meta_tags($this->link); //INSERT INTEGRITY CHECK HERE?
$keywords = $tags['keywords'];
if(count($keywords))
{
preg_match_all('/(?<=^|,)\s*((?:[^\s,]+\s*){1,4})(?=\s*(?:,|$))/', $keywords, $m);
$this->keywords = array_slice($m[1], 0, 15);
}
}
You could use the error suppression operator – the
@character – directly before the call toget_meta_tags(). This has the effect of turning all error reporting off for that line only, but it’s generally regarded as a bad practice, only to be used when you other options are all exhausted.Your first reaction to this should be to try to pass a canonical URL to
get_meta_tags()where possible – i.e. you should try to pass the URL at the end of the redirection chain: for example, link tohttp://www.php.net/manual/en/language.types.array.phprather thanhttp://php.net/array. If$this-linkcomes from a source out of your control, however, using error suppression might be your best bet:You can use it as follows:
This is functionally the same as this:
You’ll need to change the rest of your code to deal with the
$tagsvariable not containing an array of meta tags.