note 50865 added to function.get-meta-tags

From: Date: Sat, 12 Mar 2005 08:47:46 +0000
Subject: note 50865 added to function.get-meta-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-86316@lists.php.net to get a copy of this message
Tim's code is good (thanks Tim), except it won't work very well if the tag is part of a long non-breaking string. E.g. try getting the title from Google Maps (http://www.google.com/maps). A better solution is: <?php $title = ""; if ($fp = @fopen( $_POST['url'], 'r' )) { $cont = ""; // read the contents while( !feof( $fp ) ) { $buf = trim(fgets( $fp, 4096 )) ; $cont .= $buf; } // get tag contents @preg_match( "/<title>([a-z 0-9]*)<\/title>/si", $cont, $match ); // tag contents $title = strip_tags(@$match[ 1 ]); } ?> Note the strip_tags. Another thing to be careful of is to check for ", <, and >. You will need to strip those out if you are posting the output to a form. Also, it is probably best to use the /i modifier, because some people might code <TITLE> etc... ---- Manual Page -- http://www.php.net/manual/en/function.get-meta-tags.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50865 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50865&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50865&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50865&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50865&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50865&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50865&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86316) next »