Jump to content

what have i done wrong eregi_replace please help cheers...


Recommended Posts

<?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........

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........

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/]

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/]

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;

?>

 

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;

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.