You can use
echo "hello world!";
anywhere in the php program to output what you want to output.
However, you will encounter the following troubles:
1 -
When you try to add two (or more) spaces between hello and world,
you use :
echo "hello world!";
The output you get is still a space, or if you add a space at the beginning of the line,
your space will also be ignored.
2 -
What’s worse is that when outputting user input, intentional or unintentional user input will
make your output a mess and even cause trouble to other users.
For example:
If the user input has more than one line of content, then you can simply
echo $in_txt;
User line breaks will be ignored.
3 -
Still with the above example, in most cases we don’t want users to enter html
code because you don’t know what the user will enter.
Users can even write a piece of code to crash all users of your website.
Of course you don't want that, but you can't avoid it by simply
echo $in_txt;
.
Solution:
For 1, you can use ereg_replace(" {2}","$nbsp; ",$in_txt)
Two spaces together will Becomes the escape character of two spaces ($nbsp).
For 2, nl2br($in_txt) is the best choice, so all line breaks will be replaced by
"
".
For 3, safely display the html code entered by the user, there are also special functions in php.
htmlspecialchars($in_txt) will do.
In addition, if $in_txt is extracted from the mysql database, then when inserting it before,
must use addslashes(), and correspondingly, stripslashes() must be used when taking it out.
Summary:
If $in_txt is text input by the user, it can generally be output like this:
echo ereg_replace(" {2}"," ",nl2br(htmlspecialchars(stripslashes($in_txt)) ));
http://www.bkjia.com/PHPjc/316285.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316285.htmlTechArticleYou can use echo hello world!; anywhere in the php program to output the content you want to output. But you will encounter the following troubles: 1 - When you try to add two...
between hello and world