Re: For the RegExps gurus!
| From: | * R&zE: | Date: | Thu, 06 Sep 2001 17:29:50 +0000 |
| Subject: | Re: For the RegExps gurus! | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66248@lists.php.net to get a copy of this message | ||
Okay... this time an even better solution, without the /e modifier.
Think this comes pretty close to some final solution.
--- PHP code ---
<PRE>
<?php
$mem = "Hello world! http://www.helloworld.com\n
Hello world! ftp://ftp.server.com\n
Hello world www.helloworld.com";
/* ------ ! Fifth regexp ! ------ */
$pattern = array ("~\s+((?:http://|ftp://){0}(?:\w+\.)+(?:\w+))~m",
"~\s+((?:http://|ftp://)+(?:\w+\.)+(?:\w+))~m");
$replace = array (" <A href=\"http://$1\">http://$1</A>",
" <A href=\"$1\">$1</A>");
$mem = preg_replace ($pattern, $replace, $mem);
print ($mem);
?>
</PRE>
--- End of PHP code ---
This still needs some optimization imo (...)
--
* R&zE:
-- »»»»»»»»»»»»»»»»»»»»»»»»
-- Renze Munnik
-- DataLink BV
--
-- E: renze@datalink.nl
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- ««««««««««««««««««««««««