Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try html_entity_decode() with ENT_QUOTES flag

https://www.php.net/manual/en/function.html-entity-decode.php

html_entity_decode('This is an apostrophe'', ENT_QUOTES);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading