python_pardus python_pardus - 4 months ago 15
PHP Question

How to Make Str Comparison Between htmlentities and normal string in php (with non-ascii chars)

When I use this code:

<?
$a = htmlentities(urldecode("ööö"));
$b = "ööö";

if ($a === $b){
echo "equal.";
}
?>


When I runned above code, it couldn't write anything. But when I use the code below:

<?
$a = "ööö";
$b = "ööö";

if ($a === $b){
echo "equal.";
}
?>


It writes "equal". So, I can't compare strings when they are used with htmlentities function. How can I solve this problem ?
I think the problem is about htmlentities() function. When it is used, PHP can't be able to comparison strings truely...
Thanks.

Answer

Try with htmlspecialchars

<?php
    $a = htmlspecialchars(urldecode("ööö"));
    $b = "ööö";

    if ($a === $b){
            echo "equal.";
        } else {
            echo "not equal.";
    }
?>
Comments