Dynamic HTML output technology in PHP. You can use echohelloworld 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 items Between hello and world, you can use them anywhere in the php program.
Echo "hello world! ";
To output the content you want to output.
However, you may 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 you add a space at the beginning of the line,
Your spaces will also be ignored.
2-
Worse, when outputting user input content
It makes your output a mess, and even brings trouble to other users.
For example:
If the user input contains more than one row of content
Echo $ in_txt;
Line breaks are ignored.
3-
In most cases, we do not want users to input html
Code, because you do not know what the user will enter.
Users can even write a piece of code to cause all users on your website to crash.
Of course you don't want that, but if you simply
Echo $ in_txt;
It cannot be avoided.
Solution:
For 1, you can use ereg_replace ("{2}", "$ nbsp;", $ in_txt)
The two spaces are converted into escape characters ($ nbsp ).
For 2, nl2br ($ in_txt) is the best choice, so that the line feed is changed
"
.
For 3, the html code entered by the user is safely displayed, and php also has special functions.
Htmlspecialchars ($ in_txt.
In addition, if $ in_txt is proposed from the mysql database
Make sure to use addslashes (). correspondingly, stripslashes () must be used for retrieval ().
Summary:
If $ in_txt is the text entered by the user, it can be output as follows:
Echo ereg_replace ("{2}", "", nl2br (htmlspecialchars (stripslashes ($ in_txt ))));
Echo hello world !; To output the content you want to output. But you will encounter the following troubles: 1-when you try to add two...