Page 1 of 1

Regex Help

Posted: Sat Dec 11, 2010 8:59 pm
by jankidudel
Hi, I need your help. :D

Code: Select all

<?php
$content = file_get_contents('http://www.example.com' );

// Now I must to extract   all the same divs: <div class=one>div_contents</div> with their contents and save //to an array
// The problem  Is i'm bad with PCRE

preg_match_all('/^<div class=one>.*<\/div>$/' , $content, $divs);
What is wrong here ?

Re: Regex Help

Posted: Sun Dec 12, 2010 1:02 am
by requinix
Assuming example.com has HTML that's reasonably close to valid, use DOMDocument. You can find all the DIVs, then walk through and find which ones have class=one.

Re: Regex Help

Posted: Sun Dec 12, 2010 3:37 am
by s.dot
[text]/<div class=one>.*?<\/div>/is[/text]

Would probably work.