note 103552 modified in function.preg-match-all by danbrown

From: Date: Wed, 20 Apr 2011 14:27:32 +0000
Subject: note 103552 modified in function.preg-match-all by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178994@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.example.com bla bla http://www.example.net 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; ?> --was-- 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; ?> http://php.net/manual/en/function.preg-match-all.php

« previous php.notes (#178994) next »