Jump to content

Grabbing infomation between tags


Finwyn

Recommended Posts

Does it need to work recursively, e.g., finding a's in li's?

 

<pre>
<?php

$html = <<<HTML
...
<a href="http://www.phpfreaks.com">www.phpfreaks.com</a>
<ul>
	<li>Item 1</li>
	<li>Item 2</li>
	<li><a href="#Item_3">Item 3</a></li>
</ul>
...
HTML;

preg_match_all('%<(a|li).*?>(.+?)</\1>%', $html, $matches);
print_r($matches);

?>
</pre>

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.