I fetch data with cURL that I parse with DOMDocument and XPATH. strlen() is giving irregular counts.
Some intro code:
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML($data);
$xpath = new DOMXpath($dom);
I fetch the data I need and it works well, but now I need to compare two strings. Original is taken straight from a <li>-tag. Parsed is four or five <span>s joined together.
$original = $i[$n]['full'];
$parsed = $i[$n]['value'].$i[$n]['type'].$i[$n]['name'].$i[$n]['extra'];
echo $original."<br>";
echo $parsed."<br><br>";
echo strlen($original)."<br>";
echo strlen($parsed)."<br><br>";
give:
4 -5 boneless chicken breasts
4-5Boneless chicken breasts
70
27
I started messing around by replacing all spaces, trying mb_strlen with different encodings, typecasting to string, but all to no avail:
$replace = array(' ',',');
$mod_original = str_replace($replace,'',$original);
$mod_parsed = str_replace($replace,'',$parsed);
var_dump($mod_original);
echo "<br>";
var_dump($mod_parsed);
echo "<br><br>";
echo mb_strlen($mod_original,'UTF-8')."<br>";
echo mb_strlen($mod_parsed,'UTF-8')."<br>";
Results:
string(62) "4-5 bonelesschickenbreasts"
string(25) "4-5Bonelesschickenbreasts"
62
25
Something is strange. str_replace won't even remove that last whitespace.
Any help is appreciated.