array_push
| From: | John Taylor-Johnston | Date: | Sun, 02 Sep 2012 17:48:38 +0000 |
| Subject: | array_push | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318946@lists.php.net to get a copy of this message | ||
How can I clean this up?
source: http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test4.phps result: http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test4.php This is ugly. How can I clean this up like this? $mynewarray= array { [0]=> "Residential Fire Determined to be Accidental in Nature ..." [1]=> "Arrest Made in Residential Fire ..." } I wanted to push $matches[] (which I hoped was a string, not an array). I probably don't understand what preg_match_all did. Now I have arrays nested inside the array(). How can I clean it up? http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test4.phpMy approach would be to split the hole text into smaller chunks (with e.g. explode()) and extract the interesting parts with a regular expression. Maybe this will give you some ideas:2) How could I suck it into one nice easy to handle array? |$mynewarray=|array { [0]=> "Residential Fire Determined to be Accidental in Nature ..." [1]=> "Arrest Made in Residential Fire ..." } I was hoping preg_match_all would return strings. I w/as hoping |$matches[1] was a string.|/$chunks = explode("-30-", $mystring); foreach($chunks as $chunk) {preg_match_all("/News Releases\n(.+)/s", $chunk, $matches); var_dump($matches[1]);} The regex matches all text between "News Releases" and the end of the chunk.