redarrow Posted March 31, 2008 Share Posted March 31, 2008 <?php $img="[img=http://www.google.co.uk/intl/en_uk/images/logo.gif]"; $x=eregi_replace("\[img\].*\[/img\]", "<img src='$img' />",$img); echo $x; ?> result <img src='[img=http://www.google.co.uk/intl/en_uk/images/logo.gif]' /> as you can see the img /img still there shouldnt be why hair falling out........ Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/ Share on other sites More sharing options...
wmguk Posted March 31, 2008 Share Posted March 31, 2008 how about /* This will work. */ <?php $img="[img=http://www.google.co.uk/intl/en_uk/images/logo.gif]"; $string = ereg_replace('[img]', "", $img); $string = ereg_replace('[/img]', "", $img); echo $string; ?> Im a novice, but i think this should work ? <?php $img="[img=http://www.google.co.uk/intl/en_uk/images/logo.gif]"; $x=eregi_replace("\[img\].*\[/img\]", "<img src='$img' />",$img); echo $x; ?> result <img src='[img=http://www.google.co.uk/intl/en_uk/images/logo.gif]' /> as you can see the img /img still there shouldnt be why hair falling out........ Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505375 Share on other sites More sharing options...
redarrow Posted March 31, 2008 Author Share Posted March 31, 2008 it not correct lol Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505379 Share on other sites More sharing options...
wmguk Posted March 31, 2008 Share Posted March 31, 2008 it not correct lol lol, hmmm, ok, was worth a try, can you see it wont work from the code, or did it just not work when you tried it? Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505382 Share on other sites More sharing options...
sasa Posted March 31, 2008 Share Posted March 31, 2008 <?php $img="[img=http://www.google.co.uk/intl/en_uk/images/logo.gif]"; $x=preg_replace("/\[img\](.*)\[\/img\]/", "<img src='$1' />",$img); echo $x; ?>f/code] Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505384 Share on other sites More sharing options...
redarrow Posted March 31, 2008 Author Share Posted March 31, 2008 sasa what does $1 mean please provide your link you learned your programming method for preg functions please please Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505395 Share on other sites More sharing options...
sasa Posted March 31, 2008 Share Posted March 31, 2008 $1 mean 1st (and only in this case) subpatern Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505420 Share on other sites More sharing options...
redarrow Posted March 31, 2008 Author Share Posted March 31, 2008 strange behaver as posted below result........ <?php $text="[b]redarrow[/b] [i]redarrow[/i] [u]redarrow[u/]"; $bbcode=array( "<b>$1</b>"=>"/\[b\](.*)\[\/b\]/", "<i>$1</i>"=>"/\[i\](.*)\[\/i\]/", "<u>$1</u>"=>"/\[u\](.*)\[\/u\]/" ); foreach($bbcode as $key => $val){ $res=preg_replace($val,$key,$text); echo $res; } ?> output <b>redarrow</b> [i]redarrow[/i] [u]redarrow[u/][b]redarrow[/b] <i>redarrow</i> [u]redarrow[u/][b]redarrow[/b] [i]redarrow[/i] [u]redarrow[u/] Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505456 Share on other sites More sharing options...
redarrow Posted March 31, 2008 Author Share Posted March 31, 2008 tried this way aswell <?php $text="[b]redarrow[/b] [i]redarrow[/i] [u]redarrow[u/]"; $pat=array( "/\[b\](.*)\[\/b\]/", "/\[i\](.*)\[\/i\]/", "/\[u\](.*)\[\/u\]/" ); $norm=array( "<b>$1</b>", "<i>$1</i>", "<u>$1</u>" ); foreach($norm as $key){ foreach($pat as $val){ $res=preg_replace($val,$key,$text); echo $res; } } ?> <b>redarrow</b> [i]redarrow[/i] [u]redarrow[u/][b]redarrow[/b] <b>redarrow</b> [u]redarrow[u/][b]redarrow[/b] [i]redarrow[/i] [u]redarrow[u/]<i>redarrow</i> [i]redarrow[/i] [u]redarrow[u/][b]redarrow[/b] <i>redarrow</i> [u]redarrow[u/][b]redarrow[/b] [i]redarrow[/i] [u]redarrow[u/]<u>redarrow</u> [i]redarrow[/i] [u]redarrow[u/][b]redarrow[/b] <u>redarrow</u> [u]redarrow[u/][b]redarrow[/b] [i]redarrow[/i] [u]redarrow[u/] Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505460 Share on other sites More sharing options...
redarrow Posted March 31, 2008 Author Share Posted March 31, 2008 SOLVED <?php $text="[b]redarrow[/b] [i]redarrow[/i] [u]redarrow[/u]"; $pat=array( "/\[b\](.*)\[\/b\]/", "/\[i\](.*)\[\/i\]/", "/\[u\](.*)\[\/u\]/" ); $norm=array( "<b>$1</b>", "<i>$1</i>", "<u>$1</u>" ); $res=preg_replace($pat,$norm,$text); echo $res; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505465 Share on other sites More sharing options...
redarrow Posted March 31, 2008 Author Share Posted March 31, 2008 bbcode for a shoutbox i just created for learning purpose.... grate stuff i say............ <?php $text=" <br>[b]redarrow[/b] <br>[i]redarrow[/i] <br> [u]redarrow[/u] <br>[img=http://www.google.co.uk/intl/en_uk/images/logo.gif] <br>[link]www.google.com[/link] <br> [big]redarrow[/big] <br>[small]redarrow[/small] <br>[red]redarrow[/red] <br>[blue]redarrow[/blue] <br>[green]redarrow[/green]"; $pat=array( "/\[b\](.*)\[\/b\]/", "/\[i\](.*)\[\/i\]/", "/\[u\](.*)\[\/u\]/", "/\[img\](.*)\[\/img\]/", "/\[link\](.*)\[\/link\]/", "/\[big\](.*)\[\/big\]/", "/\[small\](.*)\[\/small\]/", "/\[red\](.*)\[\/red\]/", "/\[blue\](.*)\[\/blue\]/", "/\[green\](.*)\[\/green\]/" ); $norm=array( "<b>$1</b>", "<i>$1</i>", "<u>$1</u>", "<img src='$1'/>", "<a href='$1'>$1</a>", "<h1>$1</h1>", "<h4>$1</h4>", "<font color='red'>$1</font>", "<font color='blue'>$1</font>", "<font color='green'>$1</font>" ); $res=preg_replace($pat,$norm,$text); echo $res; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98758-what-have-i-done-wrong-eregi_replace-please-help-cheers/#findComment-505471 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.