note 52074 deleted from function.preg-match-all by colder

From: Date: Mon, 16 Apr 2007 16:57:36 +0000
Subject: note 52074 deleted from function.preg-match-all by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125460@lists.php.net to get a copy of this message
Note Submitter: ---- A little correction to my function below: <?php function urlhighlight($str) { preg_match_all("/http:\/\/?[^ ][^<]+/i",$str,$lnk); $size = sizeof($lnk[0]); $i = 0; while ($i < $size) { $len = strlen($lnk[0][$i]); if($len > 30) { $lnk_txt = substr($lnk[0][$i],0,30)."..."; } else { $lnk_txt = $lnk[0][$i]; } $ahref = $lnk[0][$i]; $str = str_replace($ahref,"<a href='$ahref' target='_blank'>$lnk_txt</a>",$str); $i++; } return $str; } ?> The error is in the preg_match_all("/http:\/\/?[^ ][^<]+/i",$str,$lnk); the [^<] was missing.

« previous php.notes (#125460) next »