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

From: Date: Thu, 10 May 2012 16:48:46 +0000
Subject: note 108543 modified in function.preg-match-all by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187593@lists.php.net to get a copy of this message
a few lines of code to make a url into a clickable link&#13;&#10;using lazy star (.*?) and $0&#13;&#10;&#60;?php&#13;&#10;$string = \&#39;http://www.example.com www.example.com hahahaha https://www.example.com\&#39;;&#13;&#10;&#13;&#10;$string = $string.\&#34; \&#34;;&#13;&#10;&#13;&#10;$stringall = preg_replace(\&#39;/((https:\\/\\/)|(http:\\/\\/)|(www\\.))(.*?)(?=\\s)/i\&#39;,\&#39;&#60;a href=\&#34;$0\&#34; target=\&#34;_blank\&#34;&#62;$0&#60;/a&#62;\&#39;,$string);&#13;&#10;&#13;&#10;$stringallc = preg_replace(\&#39;/(href=\\\&#34;www\\.)/i\&#39;,\&#39;href=\&#34;http://www.\&#39;,$stringall);&#13;&#10;&#13;&#10;echo $stringallc;&#13;&#10;?&#62; --was-- a few lines of code to make a url into a clickable link using lazy star (.*?) and $0 <?php $string = 'http://www.haha.com www.haha.com hahahaha https://www.haha.com'; $string = $string." "; $stringall = preg_replace('/((https:\/\/)|(http:\/\/)|(www\.))(.*?)(?=\s)/i','<a href="$0" target="_blank">$0</a>',$string); $stringallc = preg_replace('/(href=\"www\.)/i','href="http://www.',$stringall); echo $stringallc; ?> http://php.net/manual/en/function.preg-match-all.php

« previous php.notes (#187593) next »