dev.vitelline.net

php: Comparision of two strings that looks identical gives false

one more thing to my knowledge-box

Problem: a bug comparing two strings imported from Excel.

Cause: multiple spaces inside the string, which was not visible in the browser Dev-tools

Solution: To recognize the cause:

var_dump ($form["title"]);
echo ">>>";
var_dump ($counts);

Returned:

 string(19) "Sign Station Counts" >>>string(20) "Sign Station Counts" 

To fix:

$counts = preg_replace("/\s+/", " ", $counts);

Leave a Reply

Your email address will not be published. Required fields are marked *