I have been working on a script that pulls information from a certain website. The said website pulls the information from a database and displays it in a way the user can easily read it (like always).
Imagine it looks like this:
Var1: result1 Var2: result2 Var3: result3
What my script does is that it reads the page's source code and retrieves "result1", "result2" and "result3" by obtaining the text between two strings.
Sample code:
<?php
function get_string_between($string, $start, $end) {
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
function check($url) {
// usually, $fullstring = file_get_contents($url);
$fullstring = "<string1>result1</string1><string1>result2</string1><string1>result3</string1>";
$result = get_string_between($fullstring, "<string1>", "</string1>");
echo "<b>Result: </b>".$result;
}
check("random"); // just to execute the function
?>
In case you wonder why I have the check() function there it is because this code is part of something bigger and I need a solution that works in this case scenario, so I tried to keep it immaculate.
Now, I can easily get "result1" because it's the first occurrence, but how can I get "result2" and "result3"?
Thank you :)
foreach.