Jump to content

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


redarrow

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;

?>

Archived

This topic is now archived and is closed to further replies.

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