Wednesday 15 August 2012

php - Need help using explode, preg_match -



php - Need help using explode, preg_match -

i have on 1 one thousand reviews in string. have been asked see if can average rate each author. illustration of string below. have highlighted content need extract array.

shepherd's bush empire (times p54 - 4* david sinclair)grizzly bear - serpentine sessions, hyde park, london (independent viewspaper p17 - 4* elisa bray)blondie – kenwood house (sun p69 – 4* jj)jeff tweedy - union chapel, london (independent viewspaper p17 - 4* enjoli liston)tony bennett - albert hall, london (times p68 - 4* clive davis, standard p40 – 5* jack massarick

is there anyway explode string on * go 1 character , forwards words.

i know there odds these can removed later. there way of using preg_split or explode?

find single number followed asterisk, 2 words separated space

preg_match_all("/\d\* ?\w* ?\w*/", $input_lines, $output_array);

and here's illustration link http://www.phpliveregex.com/p/7ty

your output array this

array ( [0] => array ( [0] => 4* david sinclair [1] => 4* elisa bray [2] => 4* jj [3] => 4* enjoli liston [4] => 4* clive davis [5] => 5* jack massarick ) )

edit:: adding optional decimal place utilize /\d(\.\d{1,2})?\* ?\w* ?\w*/

php regex explode preg-split

No comments:

Post a Comment