Jump to content

PHP String searching


jk11uk

Recommended Posts

Hi

 

i have a php script that takes a url and loads all the code from that page into a variable.

 

I then want to scan through that variable and pick out the first 5 URLs. So i would need something which looks for the first 5 times that <a href="http://........someurl....."> happens and store the occurances into different variables.

 

 

can anyone work it out? i'm very stuck  ???

Link to comment
https://forums.phpfreaks.com/topic/89721-php-string-searching/
Share on other sites

<pre>
<?php

$data = <<<DATA
<a href="http://www.one.com">1</a>
<a href="http://www.two.com">2</a>
<a href="http://www.three.com">3</a>
<a href="http://www.four.com">4</a>
<a href="http://www.five.com">5</a>
<a href="http://www.six.com">6</a>
DATA;
preg_match_all('%<a\s.+?</a>%s', $data, $matches);
array_splice($matches[0], 5);
print_r($matches);
?>
</pre>

Link to comment
https://forums.phpfreaks.com/topic/89721-php-string-searching/#findComment-459973
Share on other sites

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.