PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Oct 20, 2018 9:05 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Sep 22, 2012 11:17 pm 
Offline
Forum Newbie

Joined: Sat Sep 22, 2012 10:45 pm
Posts: 1
HI, i am working on a project that includes HTML parsing, I want to parse the contents of a certain <div> tag. I have a parsing function to return the text between two strings using PHP functions, the problem is that inside that <div> there is another <div>
Syntax: [ Download ] [ Hide ]
<div class=anything>
...
...
<div>
...
</div>
...
</div>
 
so if I write
Syntax: [ Download ] [ Hide ]
 return_between("<div id=anything" , "</div>")

that will return the till the end of that inside div, becouse if the first closing div the program finds, not the closing of the main div. so i think that the solution lies in regex, could anyone give me an idea of how to write that expression, since i am not well trained on them.

Thank You !


Top
 Profile  
 
PostPosted: Sun Sep 23, 2012 3:35 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Regex is not good for this kind of text parsing. Use the tools that exist specifically for purposes like this: DOMDocument being the most notable.

Use a combination of getElementById(), getElementsByTagName(), and regular node traversal (like "this node's second child node") to get to where you need.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group