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

From: Date: Sun, 02 Sep 2012 14:36:06 +0000
Subject: Re: extract Occurrences AFTER ... and before "-30-"
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-318942@lists.php.net to get a copy of this message
On Sun, Sep 2, 2012 at 6:23 AM, John Taylor-Johnston <jt.johnston@usherbrooke.ca> wrote:
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
You could use substr to retrieve the rest of the string and just start over (do it in a while loop to catch all). Though, it's probably not really efficient if you have long strings. You'd be better off with preg_match. You can do it all with a single line of code, albeit that regex takes quite some time to figure out if not experienced. - Matijn PS. Please don't top post on this and probably any mailing list. Matijn, I'm a habitual top quoter. Horrible :)) But bottom quoting is not intuitive. But the are the rules, so I will be a good poster :))
I will have very, very long strings. It will be a corpus of text, of maybe 1-2 megs of text. I'm not terribly experienced. How would I "while" loop this? I am reading preg-match and the examples, but I don't really follow. http://www.php.net/manual/en/function.preg-match.php I admit, I don't know what |"/php/i"means.| |<?php // The "i" after the pattern delimiter indicates a case-insensitive search if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
    echo "A match was found.";
} else {
    echo "A match was not found.";
} ?> |

« previous php.general (#318942) next »