And here is version 5.2!

I optimized the search patterns. I found out that there was only a
very limited scope of URL's that was matched... So I pretty much
fixed that now (see the example).
Repeating elements from the patterns have been extracted and put in
an array, so that you can easily see the diff between the two
patterns. Also it's a bit easier to read this way.
Also note the adjusted test-string $mem. There are some more
realistic URL's in it than before. Just to see that they can realy
be matched.

--- PHP code ---
<PRE>
<?php

$mem = "Hello world! http://www.helloworld.com/index.html\n
Hello world! ftp://ftp-system.server.com?name=Renze%20Munnik\n
Hello world! www.helloworld.com this-is/not=a%link.\n
Hello world!
www.helloworld.com/dynamic-html/main.php?and=some%20Extra";

/* --- RE version 5.2 --- */
/* Sub patterns: */
$sub = array ("(ht|f)tp://",    /* protocols */
              "(\w+|-)+\.",     /* first (required) part of URL */
              "\w+[/?=\.%\-]*");/* rest of the URL */

/* Search-patterns: */
$pattern = array ("~\s+(($sub[0])+($sub[1])($sub[2])+)~m",
                  "~\s+(($sub[0]){0}($sub[1])($sub[2])+)~m");

$replace = array (" <A href=\"$1\">$1</A>",
                  " <A href=\"http://$1\";>http://$1</A>");

$mem = preg_replace ($pattern, $replace, $mem);


print ($mem);

?>
</PRE>
--- End of PHP code ---

-- 

* R&zE:


-- 
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to