Re: preg_match_all Help
| From: | Al | Date: | Fri, 12 Oct 2007 13:11:46 +0000 |
| Subject: | Re: preg_match_all Help | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263141@lists.php.net to get a copy of this message | ||
Assuming you know all the permissible div tag classes you want to capture the contents of....
I'd make an array list of them and the use a foreach() loop and capture the contents you want and not try to capture the contents between the channel divs. Assemble the output array inside the loop. You can also easily keep track of which channel ID the contents came from.
What you are attempting directly with preg_match_all() is possible; but, the required pattern is very messy and will be hard to test to make certain it's perfect.
admin@buskirkgraphics.com wrote:
Okay use this as an example I want put parse the html document and toss everything between the two Div class channels into an array. The problem I am having is that I cannot grab everything in between the Pattern of the preg_match_all. If I preg_match_all('/<div class="channel" [^<>]*>/i',$document,$elements); it works perfection But only arrays the single div statement not everything from div to div. I think somewhere the syntax of the preg_match_all or the implode that is not allow this function to work. Html document <div class="channel" id="one"> <div class="title"> <b>Station Manager</b> <div class="topic">Because you Can! </div> </div> </div> <div class="channel" id="two"> Php script function pullchannel($document) { preg_match_all('/<div class="channel" [^<>]*>(.*)<div class="channel" [^<>]*>/i',$document,$elements); $match = implode("\r\n",$elements[0]); $match = str_replace('"',"","$match"); return $match; } -----Original Message----- From: Jim Lucas [mailto:lists@cmsws.com] Sent: Thursday, October 11, 2007 9:41 PM To: admin@buskirkgraphics.com Cc: php-general@lists.php.net Subject: Re: [PHP] preg_match_all Help admin@buskirkgraphics.com wrote:I have tried this many way and for some reason I cannot pull content between the 2 pattern options. function pullchannel($document) {Give us and example of the input data. And tell us from that example, what it is you are expecting to extract from it. Jimpreg_match_all('/<div class="channel" [^<>]*>(.*)<divclass="channel" [^<>]*>/i',$document,$elements); $match = implode("\r\n",$elements[0]); $match = str_replace('"',"","$match"); return $match; }