Click to See Complete Forum and Search --> : Find a special character in a string


ma3743
11-20-2007, 04:58 AM
I have a string like this:
$str = "2|345 1|50 2|1461 3|555 ";
pattern is level|id
And I want delete an level|id from this string
But my problem is that is just know ID but not level
$ID = "1461";
$lookfor = "X|" . $ID . " ";
$newstr = str_replace($lookfor, "", $str);

And I want get this:
$ newstr = "2|345 1|50 3|555 ";
How can I do that?
Tanks in advance

gpm1982
11-20-2007, 08:35 AM
$str = "2|345 1|50 2|1461 3|555 ";
$ID = "1461";
$newstr = preg_replace("#\d+\|{$ID}#", "", $str);
echo $newstr;

ma3743
11-20-2007, 08:51 AM
tank you dear gpm1982