You are here: Re: regex negative look behind not working « PHP Programming Language « IT news, forums, messages
Re: regex negative look behind not working

Posted by Chung Leong on 09/13/05 23:48

That doesn't work, because the pattern will match again as soon as the
regexp engine looks one letter to the right.

The bracketed letter below indicates the first letter of a possible
match. The following fails the lookbehind assertion, because "mailto:"
matches the condition:

mailto:[c]hernyshevsky@hotmail.com

The following does not fail the assertion, as "mailto:c" is not a
match:

mailto:c[h]ernyshevsky@hotmail.com


A job like this is easier with preg_replace_callback(), arguably the
most powerful text manipulation function in PHP. Example:

function antispam($m) {
return ($m[1]) ? $m[0] :
"<script>document.write('<a
href=\'mailto:'+'{$m[3]}'+'@'+'{$m[4]}'+'\'>'+'$m[3]'+'@'+'$m[4]'+'</a>');</script>";
}

preg_replace_callback('/(mailto:)?\s*(([_\\.0-9a-z-]+)@([_\\.0-9a-z-]+))/i',
'antispam', $string);

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация