Home  >  Article  >  Backend Development  >  How to use PHP escape characters to solve code conversion problems_PHP tutorial

How to use PHP escape characters to solve code conversion problems_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:29:00916browse

LearningSystem: linux php4 oracle8i

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><strong><font color="#006699"><?</FONT></STRONG></SPAN><SPAN> </SPAN></SPAN><LI class=""><SPAN>//--标题,名字等字段入库处理(去首尾空格)  </SPAN><LI class=alt><SPAN>function trans_string_trim($str) {  </SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>str</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>trim</FONT></SPAN><SPAN>($str);  </SPAN></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>str</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>eregi_replace</FONT></SPAN><SPAN>("'","''",$str);  </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>str</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>stripslashes</FONT></SPAN><SPAN>($str);  </SPAN></SPAN><LI class=alt><SPAN>return $str;  </SPAN><LI class=""><SPAN>}  </SPAN><LI class=alt><SPAN> </SPAN><LI class=""><SPAN>//--文章入库处理,即textarea字段;  </SPAN><LI class=alt><SPAN>function trans_string($str) {  </SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>str</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>eregi_replace</FONT></SPAN><SPAN>("'","''",$str);  </SPAN></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>str</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>stripslashes</FONT></SPAN><SPAN>($str);  </SPAN></SPAN><LI class=""><SPAN>return $str;  </SPAN><LI class=alt><SPAN>}  </SPAN><LI class=""><SPAN> </SPAN><LI class=alt><SPAN>//--从库中显示在表单中;在text中以trans转换,在textarea中,无需转换,直接显示  </SPAN><LI class=""><SPAN> </SPAN><LI class=alt><SPAN>//--显示在WEB页面,过滤HTML代码;包括链接地址  </SPAN><LI class=""><SPAN>function trans($string) {  </SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>string</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>htmlspecialchars</FONT></SPAN><SPAN>($string);  </SPAN></SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>string</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>ereg_replace</FONT></SPAN><SPAN>(chr(10),"</SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></font></strong></span><span>",$string);  </span></span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">ereg_replace</font></span><span>(chr(32)," ",$string);  </span>
</li>
<li class=""><span>return $string;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>//--显示在WEB页面,不过滤HTML代码;  </span></li>
<li class=""><span>function trans_web($string) {  </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">ereg_replace</font></span><span>(chr(10),"</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></span></font></strong><span>",$string);  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">ereg_replace</font></span><span>(chr(32)," ",$string);  </span>
</li>
<li class="alt"><span>return $string;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>//--显示在WEB页面,过滤HTML代码及头尾空格,主要用于显示用户昵称  </span></li>
<li class="alt"><span>function trans_trim($string) {  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">trim</font></span><span>($string);  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">htmlspecialchars</font></span><span>($string);  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">ereg_replace</font></span><span>(chr(10),"</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></span></font></strong><span>",$string);  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">ereg_replace</font></span><span>(chr(32)," ",$string);  </span>
</li>
<li class=""><span>return $string;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>//--显示在span中;  </span></li>
<li class=""><span>function trans_span($string) {  </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">ereg_replace</font></span><span>(chr(10),"n",$string);  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">ereg_replace</font></span><span>(chr(32)," ",$string);  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">string</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">ereg_replace</font></span><span>('"',""",$string);  </span>
</li>
<li class=""><span>return $string;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>//--在WEB上显示cookie,过滤html  </span></li>
<li class=""><span>function trans_cookie($str) {  </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">str</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">trans</font></span><span>($str);  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">str</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">stripslashes</font></span><span>($str);  </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">str</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">eregi_replace</font></span><span>("''","'",$str);  </span>
</li>
<li class=""><span>return $str;  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>

Finally, I would like to add one more point about the usage of PHP escape characters. If a paragraph in the article is displayed in span, substr is used to obtain a fixed-length string. , remember to add an extra space after the span parameter, otherwise the html code will be messed up when half a Chinese character is cut off.

The above is the solution we provide to you about PHP escape characters to solve code conversion problems.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446402.htmlTechArticleI learned the system: linux php4 oracle8i? //-- Title, name and other fields are stored in the database (remove the first and last) space) functiontrans_string_trim($str){ $ str = trim ($str); $ str = eregi_replace ("'"...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn