<Original message>
From: _lallous <[EMAIL PROTECTED]>
Date: Thu, Sep 06, 2001 at 11:34:45AM +0200
Message-ID: <[EMAIL PROTECTED]>
Subject: Re: [PHP] For the RegExps gurus!

> > Ehh... no. How would you implement an if-statement then?
> I thought I could have build a regexp that allow you to specify a default
> value of a subset if it was not matched...
> and it seems there is no way then!
> 
> Thanks Renze.

</Original message>

<Reply>

Okay... I found a different way. I don't actually think this is
better, but the regexp is some what more pure:

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

$mem = "Hello world! http://www.helloworld.com\n
Hello world! ftp://ftp.server.com\n
Hello world www.helloworld.com";

/* ------ ! Here's the old regexp ! ------ */
// $mem = preg_replace ("/\s+([http:|ftp:]{0,1}\S+\.\S+)/me", "' <A
// href=\"'.
//      (ereg('^[http:|ftp:]','\\1')
//              ? '\\1\">\\1</A>'
//              : 'http://\\1\";>http://\\1</A>')", $mem);

/* ------ ! Here's the new regexp ! ------ */
// Need an associative array...
$repl = array ("" => "http://";,
               "http://"; => "http://";,
               "ftp://"; => "ftp://";);
// The regexp itself:
$mem = preg_replace ("/\s+([http:|ftp:]*(\/\/)*)(\S+\.\S+)/me",
        "' <A href=\"'.\$repl['\\1'].'\\3\">'.\$repl['\\1'].'\\3</A>'",
        $mem);

print ($mem);

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

I'll let you know when I find a better way... I think there must be
one...

</Reply>

-- 

* 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