note 108543 modified in function.preg-match-all by danbrown
| From: | danbrown@php.net | 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 using lazy star (.*?) and
$0 <?php $string = \'http://www.example.com www.example.com hahahaha https://www.example.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; ?>
--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