PHP compare values with HTML special characters

I am trying to compare rows from 2 PHP arrays like this…

if ($row1[$i] == $row2[$i]) {
    echo 'Rows match';
} else {
    echo 'Rows do not match';

This is working correctly until it comes across something that is encoded, so apostrophe is a good example. So the below 2 are not equal…

This is an apostrophe'
This is an apostrophe'

I have tried using htmlspecialchars_decode to attempt to convert them before comparing but this is not working. How can I compare these 2 rows?

>Solution :

Try html_entity_decode() with ENT_QUOTES flag

html_entity_decode('This is an apostrophe'', ENT_QUOTES);

Leave a Reply