How PHP uses custom functions to convert HTML tags

Source: Internet
Author: User
This article mainly introduces the PHP custom function to transform the HTML tag method, combined with the instance form analysis PHP code conversion and regular replacement operation skills for the string, the need for friends can refer to the following

The example in this article describes how PHP custom functions convert HTML tags. Share to everyone for your reference, as follows:

<?php/** Created on 2016-9-29**/$orig = "I/ll \" Walk\ "the <b>dog</b> now"; $a = htmlentities ($orig); $b = HT Ml_entity_decode ($a); Echo $a; I ' ll &quot;walk&quot; The &lt;b&gt;dog&lt;/b&gt; Nowecho $b; I ' ll "walk" the <b>dog</b> now//for users prior to PHP 4.3.0 you could do this:function unhtmlentities ($stri NG) {  //Replace numeric entities  $string = preg_replace (' ~& #x ([0-9a-f]+); ~ei ', ' Chr (Hexdec ("\\1")) ', $ string);  $string = Preg_replace (' ~&# ([0-9]+); ~e ', ' Chr ("\\1") ', $string);  Replace literal entities  $trans _tbl = get_html_translation_table (html_entities);  $trans _tbl = Array_flip ($trans _tbl);  Return Strtr ($string, $trans _tbl);} $c = unhtmlentities ($a); Echo $c; I ' ll "walk" the <b>dog</b> now?>

The results of the operation are as follows:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.