English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

how come you can't store the character < in a php variable? I need to if someone knows a way

2007-02-17 05:07:51 · 3 answers · asked by amy a 1 in Computers & Internet Programming & Design

3 answers

If < is a reserved character in PHP then you need to 'escape' it i.e. represent the character in a different way. There are two escape codes listed for that character here:

http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php

2007-02-17 05:17:49 · answer #1 · answered by Bamba 5 · 0 1

Allow me to give you an example:

--------------------------------------------------
hello!
$text = "hellohello!
";
$text = str_replace(array('<','>'), array('& lt ;','& gt ;'), $text);
echo $text;

?>
blah!
-----------------------------------------

Try running that code
IMPORTANT: Remove the spaces between '& lt ;' as well as between '& gt ;'


The problem is NOT that those characters cannot be stored in a variable, it's that echoing them directly with a string inside will lead to the HTML trying to interpret it, whereas if you use the replace method (or have it insert the HTML entity code in the first place) you won't have this problem.

2007-02-17 13:23:38 · answer #2 · answered by Anonymous · 1 0

You can. The following code runs fine with me.
$chVal = "<";
echo $chVal;
$chVal = ">";
echo $chVal;
?>

2007-02-20 03:51:30 · answer #3 · answered by Atif Majid 3 · 0 0

fedest.com, questions and answers