Page 1 of 1

regex pb !

Posted: Tue Jun 04, 2002 9:47 am
by aegypius
Hi !

I have a problem using regex expressions. I try to manage themes from my php code and gfx links are giving a headache !

here's a sample of what i try to do :

<[whatever] src="[whatever]" [whatever]> replaced by
<^^^^^^^ src="[new dir][same as above]" ^^^^^^^^>

and here's my code :

Code: Select all

$outfile = eregi_replace("<&#1111;:ascii:]*&#1111;src="]&#1111;:ascii:]*&#1111;"]&#1111;:ascii:]*>","<img src="".TEMPLATE_PATH."$this->theme/", $outfile);
it doesn't work !

Could You help me please !

I 'm getting mad :evil:

aegypius

Posted: Tue Jun 04, 2002 4:28 pm
by volka

Code: Select all

<?php
$TEMPLATE_PATH = 'anotherdir/';
$html = file('input.html');
$search = '/<img (.*)src="(.*)"(.*)>/';
$replace = "<img \\1src="$TEMPLATE_PATH\\2"\\3>";
$html = preg_replace($search, $replace, $html);
foreach($html as $line)
	print($line);
?>
will replace the src of <img>-Elements

a more efficient way to do that

Posted: Wed Jun 05, 2002 4:40 am
by aegypius

Code: Select all

$outfile=eregi_replace("<(&#1111;^>]*|&#1111;:space:]*)src=('|")(&#1111;^<]*)('|")(&#1111;^<]*|&#1111;:space:]*)>","<\\1src=\\2".TEMPLATE_PATH."$this->theme/\\3\\4>",$outfile);
And now it works with <script src= and javascrits like img.src !

Thanks for your help !

aegypius

a new version

Posted: Wed Jun 05, 2002 7:40 am
by aegypius

Code: Select all

$outfile=eregi_replace("<(&#1111;^frame]+&#1111;^>]*|&#1111;:space:]*)src=('|")(&#1111;^http://]+&#1111;^ftp://]+&#1111;^<]*)('|")(&#1111;^<]*|&#1111;:space:]*)>","<\\1src=\\2".TEMPLATE_PATH."$this->theme/\\3\\4>",$outfile)
This version fix various pb with frame and absolute url !

Have Fun !

aegypius