PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
aegypius
Forum Newbie
Posts: 3 Joined: Tue Jun 04, 2002 9:47 am
Post
by aegypius » Tue Jun 04, 2002 9:47 am
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("<ї:ascii:]*їsrc="]ї:ascii:]*ї"]ї:ascii:]*>","<img src="".TEMPLATE_PATH."$this->theme/", $outfile);
it doesn't work !
Could You help me please !
I 'm getting mad
aegypius
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Jun 04, 2002 4:28 pm
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
aegypius
Forum Newbie
Posts: 3 Joined: Tue Jun 04, 2002 9:47 am
Post
by aegypius » Wed Jun 05, 2002 4:40 am
Code: Select all
$outfile=eregi_replace("<(ї^>]*|ї:space:]*)src=('|")(ї^<]*)('|")(ї^<]*|ї: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
aegypius
Forum Newbie
Posts: 3 Joined: Tue Jun 04, 2002 9:47 am
Post
by aegypius » Wed Jun 05, 2002 7:40 am
Code: Select all
$outfile=eregi_replace("<(ї^frame]+ї^>]*|ї:space:]*)src=('|")(ї^http://]+ї^ftp://]+ї^<]*)('|")(ї^<]*|ї:space:]*)>","<\\1src=\\2".TEMPLATE_PATH."$this->theme/\\3\\4>",$outfile)
This version fix various pb with frame and absolute url !
Have Fun !
aegypius