Re: extract Occurrences AFTER ... and before "-30-"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




See:
http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test.php
http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test.phps

In $mystring, I need to extract everything between "|News Releases|" and
"-30".

The thing now is $mystring might contain many instances of "|News
Releases|"
and "-30".

How do I deal with this? My code only catches the first instance.

Thanks for you help so far.

John

I do find it intuitive actually, when reading things back your answer is after the question, which makes sense. The other way around doesn't?
I'll never get it. Newest work on top of the pile, instead of digging :))
On Sun, Sep 2, 2012 at 4:33 PM, Frank Arensmeier <farensmeier@xxxxxxxxx> wrote:
My 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:
$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.
It shouldn't be needed to explode the string first, you could do that
with a single preg_match_all. (Sorry, can't remember how anymore, it's
been a while since I last used PCRE ).
I'll get the PCRE eventually. Never had much time for PERL after PHP stated anyhow :)p


I think the split by -30- works nicely.


2) How could I suck it into one nice easy to handle array? http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test2.php

|$mynewarray=|array {
  [0]=> "Residential Fire Determined to be Accidental in Nature ..."
  [1]=> "Arrest Made in Residential Fire ..."
}


Thanks,
John

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux