0

Ran into an issue today with PHP and string interpretation.

I have a variable that stores a string and I need that string to be interpreted by PHP to replace special characters inside of it like new lines, tabs, hex, etc. I know this can be done by placing double quotes around the string I declared as $test, however this is not always an option for strings that are already declared.

Is there a way I can have PHP re-interpret an already declared string?

See below:

http://php.net/manual/en/language.types.string.php

Example:

<?php

$test = '\x68\x65\x6C\x6C\x6F';

if ("$test" === '\x68\x65\x6C\x6C\x6F') //echos true, even with double quotes around the variable
{
    echo 'true';
}
else if ("$test" === 'hello') //How can I get this condition to be true rather than the previous statement without placing double quotes around my original string I declared?
{
    echo 'false';
}

?>

Update:

Solution is to use stripcslashes(), as it will convert escape sequences in an already declared string. Thank you @Edgars WEBHAUS

DropItLikeItsHot
  • 139
  • 1
  • 14

0 Answers0