note 103552 added to function.preg-match-all
| From: | info at zenworks dot it | Date: | Wed, 20 Apr 2011 08:31:44 +0000 |
| Subject: | note 103552 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178984@lists.php.net to get a copy of this message | ||
Just few lines of code to convert in a clickable link with tag <a>
the pattern "http://......." in a string:
<?php
$stringa = " bla bla bla http://www.zenworks.it bla bla http://www.google.it bla bla bla";
$m = preg_match_all('/http:\/\/[a-z0-9A-Z.]+(?(?=[\/])(.*))/', $stringa,
$match);
if ($m) {
$links=$match[0];
for ($j=0;$j<$m;$j++) {
$stringa=str_replace($links[$j],'<a
href="'.$links[$j].'">'.$links[$j].'</a>',$stringa);
}
}
echo $stringa;
?>
----
Server IP: 81.88.49.40
Probable Submitter: 194.243.52.171
----
Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php
Edit -- https://master.php.net/note/edit/103552
Del: integrated -- https://master.php.net/note/delete/103552/integrated
Del: useless -- https://master.php.net/note/delete/103552/useless
Del: bad code -- https://master.php.net/note/delete/103552/bad+code
Del: spam -- https://master.php.net/note/delete/103552/spam
Del: non-english -- https://master.php.net/note/delete/103552/non-english
Del: in docs -- https://master.php.net/note/delete/103552/in+docs
Del: other reasons-- https://master.php.net/note/delete/103552
Reject -- https://master.php.net/note/reject/103552
Search -- https://master.php.net/manage/user-notes.php