Regex Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jankidudel
Forum Commoner
Posts: 91
Joined: Sat Oct 16, 2010 4:30 pm
Location: Lithuania, Vilnius

Regex Help

Post 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 ?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Regex Help

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Regex Help

Post by s.dot »

[text]/<div class=one>.*?<\/div>/is[/text]

Would probably work.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply