Thursday, November 02, 2006

PHP Extract a String that does not Match a given String of Text

PHP Extract a String that does not Match a given String of Text

Use explode, to strip and remove a line of text or word that matches "Foo"

$string = "Test Foo Bar";
$split = explode("Foo",$string);
$strip0 = $split[0];
$strip1 = $split[1];

echo "$strip0"; => Test
echo "$strip1"; => Bar
The [0] var gets the char previous to the match
The [1] var gets the char after the match

No comments: