Jump to content

Recommended Posts

I have a div that I'm trying to extract content from, however I'm having a bit of trouble. This div is obviously going to have more values within the div.

 

<div id="babyblue">lots of <b>random</b> stuff going on in here.. wanna grab it all</div>

 

How would one go about this?

Link to comment
https://forums.phpfreaks.com/topic/162146-extracting-div-contents/
Share on other sites

Alright, so after some investigating as to why this wasn't working.. it appears in some of the divs there's actually more divs inside.. therefore it could read a div inside of the div I'm trying to get and close early.

 

Would using DOM actually solve my problem here? The thing is, I've never used DOM in my life and I have no idea how I would set that up.

But you said earlier...

Also, forgot to mention that I can't use DOM in this case.. has to be regex.

 

anywhoo....yes, the problem is that regex does not handle nested tagging very well.  More accurately, it handles it very poorly.  The core of DOM is in fact regex, but the broader scope of DOM is that it goes through and creates a well, model (hence the name) of the page, as a whole.  So it properly matches opening/closing tags up by looking at the document as a whole. 

 

So you can use regex, but in order to make it any kind of accurate, you're going to have to look at the content as a whole and walk through everything matching them up...which is reinventing the wheel. 

 

There is already another active thread about DOM on this very page that looks suspiciously familiar to this thread (trying to get contents of a div...asking for a regex solution, being told about DOM...hmm...not insinuating anything..just..awfully coincidental...).  Anyways..it's on the front page of the forum, so look into how to do the whole DOM thing there. 

 

edit: in fact, I'll even give you a link to it, save yourself the trouble of trying to find it.  http://www.phpfreaks.com/forums/index.php/topic,256532.0.html

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.