View Single Post
  #4 (permalink)  
Old November 6th, 2003, 12:33 AM
richard.york's Avatar
richard.york richard.york is offline
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Thanks Nik,

I must have overlooked the pattern syntax links when I was looking through the manual. I have been trying out some patterns.

I saw in the user notes at http://www.php.net/preg_replace_callback someone suggested plugging in an array with two indices, the first being the class name and the second the function name.. well actually here is a quote:

Quote:
quote:
Also, if you want to use a *static* class method for the callback function, you can refer to it like this:
   preg_replace_callback(pattern, array('ClassName', 'methodName'), subject)

In PHP5, from within the class:
   preg_replace_callback(pattern, array('self', 'methodName'), subject)
I tried this and it works, well the first method, I'm waiting for PHP 5 to come out of beta before fooling with that.

I have been pouring over your syntax for a while and cannot seem to get it modified to accept any protocol.

The original I think was this:
$pattern = '!\bhttps?://([\w\-]+\.)+[a-zA-Z]{2,3}(/(\S+)?)?\b!';

I tried changing it to this:
$pattern = '!\b(https?|telnet|ftp)(:\/\/)([\w\-]+\.)+[a-zA-Z]{2,3}(/(\S+)?)?\b!';

And I was also trying to include an optional '/' at the end of the URL... for cases where the url contains only http://www.somesite.com/

I wrote this one for emails which seems to work well... actually I took the example on the zend website and modified it to include more addresses.

$body = preg_replace_callback('/[A-z0-9_\-\.]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z0-9\-]+([.][A-z0-9_\-]+)?+[A-z]?/', array('library', 'mailify'), $body);

It matches dots in the address and optionally matches sub-domain addresses or double suffix domains, like .co.uk and it matches addresses attached to a mailto: statement.

I would appreciate any comments you might be able to throw my way!

Thanks!
: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote