Since the other data get found correctly, the function is not the problem.
That suggests that the data is the problem.
I again suggest that the records being checked are not exactly what you expect.
For example, I can replicate failure by change "Mileage" to "mileage" in your data record. Or "Location" to "location". Be VERY careful checking the data records therefore: Location : is not the same as Location:, etc.
I added an error trap to your function to alert to problems:
function get_between ($text, $s1, $s2) {
$mid_text = "";
$pos_s = strpos($text,$s1);
$pos_e = strpos($text,$s2);
for ( $i=$pos_s+strlen($s1) ; ( ( $i < ($pos_e)) && $i < strlen($text) ) ; $i++ ) {
$mid_text .= $text[$i];
}
if(!$midtext||!$pos_e||!$pos_s){
$mid_text= "<h2>Problem: \$pos_s is $pos_s, \$pos_e is $pos_e</h2>";
}
return $mid_text;
}
An alternate suggestion is that you have some code that you have not posted, and that the problem is there. In this case, you might be unintentionally modifying your search terms, which would have the same effect as inconsistent data from the remote site.
I would therefore check all other unposted code in the loop very carefully for all instances where $mileage, $location may be changed-- perhaps you are unwittingly changing the definition of the search string "Mileage:"
Finally you can simplify your get_between function:
function get_between ($text, $s1, $s2) {
$start=strpos($text,$s1)+strlen($s1);
$end=strpos($text,$s2)-$start;
$mid=substr($text,$start,$end);
return $mid;
}
Or REALLY simplify it:
function get_between ($text, $s1, $s2) {
return substr($text,strpos($text,$s1)+strlen($s1),strpos($text,$s2)-(strpos($text,$s1)+strlen($s1)));
}