Jump to content

Parsing Text


d_barszczak

Recommended Posts

Hi all,

 

I am developing a simple seach engine script that puts words found in a html document into a table notes the url and the occourances. What i would like it to do is find any hyperlinks that are in the html document and im not sure how to pick out the hyperlinks and place them in an array.

Link to comment
https://forums.phpfreaks.com/topic/57541-parsing-text/
Share on other sites

<pre>
<?php

$html = <<<HTML
<ul>
	<li><a href="http://www.google.com">Google</a></li>
	<li><a href="http://www.letspolka.com">Let's Polka</a></li>
	<li><a href='http://www.neatorama.com'>Neatorama</a></li>
	<li><a href=http://www.phpfreaks.com>PHP Freaks</a></li>
</ul>
HTML;

preg_match_all('/(?<=href=)[\'"]?([^\s"\'>]+)/', $html, $matches);
array_shift($matches);
print_r($matches);

?>
</pre>

Link to comment
https://forums.phpfreaks.com/topic/57541-parsing-text/#findComment-284833
Share on other sites

  • 4 weeks later...

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.