Jump to content

Grab content in the div


nareshrevoori

Recommended Posts

 

I've been trying to figure out this but nothing helps :(

 

I am not very good with Regx. I want to grab the content (text to grab & date part ) in the 2nd <div class="section"> and put them in a php array.

 

 

$html = '<div class="pad">
<div class="section">
	<div class="section_title">Title text</div>
</div>
<div class="section border_top">
	<div><small>Info.</small></div>
</div>
<div class="section">
	<div class="section border_top"> <a href="#">link</a> text to grab <small>12/2/2009</small></div>
	<div class="section border_top"> <a href="#">link</a> text to grab <small>12/2/2009</small></div>
	<div class="section border_top"> <a href="#">link</a> text to grab <small>12/2/2009</small></div>
	<div class="section border_top"> <a href="#">link</a> text to grab <small>12/2/2009</small></div>
	<div class="section border_top"> <a href="#">link</a> text to grab <small>12/2/2009</small></div>
</div>
</div>';

 

thanks for your help.

 

Link to comment
https://forums.phpfreaks.com/topic/183683-grab-content-in-the-div/
Share on other sites

If you don't use PHP 5 you really should consider upgrading. There is always DOMXML, which is the suggested alternative for PHP 4. Of course it can be done with Regular Expressions, but we would need to know how accurate your example is. For example is the date always inside <small> tags? Is the href of the anchor links always # (I assume not)? Same applies for the anchor link text. What characters can be included in "text to grab"? Will it include any tags or special tag characters (> < etc)?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.