php - Split string between two characters? -
OK, it should be incredibly easy, but I do not know what I'm looking for ...
I want to split a string between two letters
$ string = "blah blah blah blah blah blo blah blah (bam)"; Returns: Array 1 - & gt; Bloper 2 - & gt; Bloop3 - & gt; Thanks
Arthur
< P> You can do this with regular expressions: $ string = "blah blah blah blah blah blah blah blah"; Preg_match_all ("/\((.*?)\)/", $ string, $ result_array); Print_r ($ result_ar [1]); // $ result_array [0] contains matches with feet
This output will be:
Array ([0] = & gt; Blopper [ 1] = & gt; bloop [2] = & gt; bam)
My regular expression uses the non-greedy selector: (. *?)
Which means that as low as possible, It keeps all this stuff from )
and grabbing everything between (
and closing )
to open it? How many words are there?
Comments
Post a Comment