How can I check in PHP if every text row starts with Foo?
I want to remove “Foo” at the beginng of rows, but only if every row starts with Foo.
$string = 'Foo A
Foo B
Foo C';
should return:
A
B
C
and
$string = 'Foo A
B
Foo C';
should return:
Foo A
B
Foo C
How could this be matched?
if ( preg_match("/^Foo/m", $string ) ) {
$string = preg_replace('/^Foo /m', '', $string);
}
This matches only single rows, but as mentioned it should only apply if all rows start with “Foo “.
I modified the regex a bit to assert every line starts with
"Foo".http://codepad.viper-7.com/ail50t