PHP string does not allow <and> characters

I have a line in my code in the following example:

<?php
$find = '<tag';
$string = 'blah blah <tag=something>';
?>

Simple enough, but when I try to repeat the lines, it doesn't like <or> characters. All that receives an echo is:

blah blah

So basically I assume that I need to avoid these characters in order to make them work in PHP, but I don’t know exactly how to do this. I use this for the template system, so in the html file the file can be included using:

<include="filename.html">

Therefore, I do not need to show <and> characters on the screen at any time, I just need to read the file, find instances of these tags and do some magic. I have everything that works, but it's just any line that contains more / less than statements that don't seem to work fine.

Any ideas?

+5
4

PHP HTML, HTML- (< > ). HTML, HTML-. , .

:

&gt;     : > (greater-than)
&lt;     : < (less-than)
&amp;    : & (ampersand)
&raquo;  : » (right angle quote marks)
&eacute; : é (e acute)

, . , > , URL URL.

, .

<?php
$find = '&lt;tag';
$string = 'blah blah &lt;tag=something&gt;';
?>

, htmlspecialchars() (, ).

<?php echo htmlspecialchars($string); ?>

blah blah <tag=something> -. PHP , , .

+13

HTML, HTML.

:

echo htmlspecialchars("<hello>");
+4

htmlspecialchars()

echo htmlspecialchars('string you want to echo');
+4

you can use the htmlspecialchars function to avoid <Brackets ..

+1
source

All Articles