user982124
user982124

Reputation: 4610

PHP - HTML Entities/Special Chars Confusion

I'm working with a database and comparing values to strings to then create new records. I've encountered an issue with a comparison with a database value that is stored in a $type variable - the offending value is:

<recordID>

In my PHP script I do a test to see if the database value = "":

if ($type == '<recordID>') {
// create new records etc
}

however I've just noticed this test is failing, and I'm assuming it's the "<" and ">" characters that is the issue. If I echo the $type variable I get this in the browser source view:

&lt;contactID&gt;

I can see the issue relates to htmlentities and html special chars but I haven't been able to work out the function to use to be able to get this comparison above to work.

Upvotes: 0

Views: 37

Answers (1)

Manikiran
Manikiran

Reputation: 1

You can use builtin for it

<?php
echo htmlspecialchars_decode($type);
?>

Upvotes: 1

Related Questions