bastien wrote:why strpos? why not either regex (preg_replace) or str_replace?
Hi, I'm using str_replace() to, but first i need to extract the data between the tags, to do that i need to get the start and end positions, eg using strpos().
Here is my function for finding and replacing multiple image tags in a string;
function Convert_IMG($msg)
{
$tag1 = '[IMG]';
$tag2 = '[/IMG]';
$Run = true;
while ($Run)
{
$pos1 = strpos($msg, $tag1);
$pos2 = strpos($msg, $tag2);
if($pos1==true){
if($pos2==true){
$img = substr($msg, $pos1 + strlen($tag1), $pos2 - strlen($tag1) -$pos1);
$img_new = '<img src="' . $img . '" alt="' . $img . '" />';
$img_old = $tag1 . $img . $tag2;
$msg = str_replace( $img_old, $img_new, $msg);
}else{
$Run = false;
}
}else{
$Run = false;
}
}
return $msg;
}
Wich never made any problems before, it always worked, it is just now when i'm parsing a string that I pulled out a table then the strpos() always is returning false, even tough the tags are in the parsed string.