You are here: Re: PCRE - Negative Lookbehind Assertion problem « PHP Programming Language « IT news, forums, messages
Re: PCRE - Negative Lookbehind Assertion problem

Posted by Jim on 10/29/07 21:05

I just spotted one error, the equals sign after the negative
lookbehind, although that seems to have made little difference.
Updated code follows:

<?php

$prefix = 'http://mydomain.com/';

$content = <<<EOT
<img src="images/test.gif" alt="Test Image" />
<img src="http://shouldnt.be.changed/images/test.gif" alt="Test
Image" />
EOT;

echo preg_replace('/\<img(.+?)src="(?<!http)(.+?)"(.+?)\/>/', '<img
$1src="' . $prefix . '$2"$3/>', $content);

/*
* First img element's src attribute should be
* changed, but not the second's.
*/

?>

 

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

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