Extract part of a string
Posted: Sun Oct 28, 2007 3:48 pm
Hi,
I am looking for a code that can grab everything in between the brackets corresponding to a certain variable ($name).
For example, if my string is
$string =
"John{
john is a brown worm
}
Laura{
nancy is a blue pig
}";
and $name = "John", what I want returned is "john is a brown worm";
$name can equal Laura too, or any other name, in a list of n names, so John doesn't have to be the first name.
And the contents within the brackets can span multiple lines.
I am trying to do it with preg_match but it's not working.
Thanks for your help!
I am looking for a code that can grab everything in between the brackets corresponding to a certain variable ($name).
For example, if my string is
$string =
"John{
john is a brown worm
}
Laura{
nancy is a blue pig
}";
and $name = "John", what I want returned is "john is a brown worm";
$name can equal Laura too, or any other name, in a list of n names, so John doesn't have to be the first name.
And the contents within the brackets can span multiple lines.
I am trying to do it with preg_match but it's not working.
Thanks for your help!