1

The variable $page includes a webpage (full HTML file), but I want to filter that file on this line:

<a href="http://[website]/[folder]/

And I want that the 5 characters after parsed in a string.

But that strings is multiple times inside $page, so the numbers has to be stored in an array too.

So if a match is found with <a href="http://[website]/[folder]/23455, how do I get the '23455' into $nums[0]

And if another match is found with <a href="http://[website]/[folder]/12345, the '12345' will be put into $nums[1]

Jers
  • 221
  • 4
  • 14

2 Answers2

2

Take a look at http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/ maybe this regular expression works for you:

/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ 
Lobo
  • 4,001
  • 8
  • 37
  • 67
0

From what I understand from your question you are just trying to get the ending piece of the url and then do a comparison then store the value in an array? I believe this code should do the trick.

$nums = new array(); //declare your array
$a = new SimpleXMLElement('<a href=<a href="http://[website]/[folder]/23455">Your Link</a>'); //create a new simple xml element
$a = $a['href'];
$array = explode("/",$a); //split the string into an array by using the / as the delimiter

if($array[count($array)-1] == '23455') { //get the count of the array and -1 from the count to get the last index then compare to required number
$nums[0] = '23455'; //store value in array
} else if ($array[count($array)-1] == '12345'{
$nums[1] = '12345'; //
}
Camrin Parnell
  • 433
  • 2
  • 9
  • 21