PHP Custom Function Transform HTML tag example _php tips

Source: Internet
Author: User

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

<?php
/* Created on 2016-9-29
*
*
/$orig = "I ll \" Walk\ "the <b>dog</b> Now";
$a = htmlentities ($orig);
$b = Html_entity_decode ($a);
echo $a; I ' ll &quot;walk&quot; The &lt;b&gt;dog&lt;/b&gt; Now
echo $b;//I'll "walk" the <b>dog</b> now
//for users prior to PHP 4.3.0 your may does this:
function Unhtmlentities ($string)
{
  //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 shown in the following illustration:

For more information about PHP interested readers can view the site topics: "PHP coding and transcoding Operation tips Summary", "PHP object-oriented Programming Introduction Course", "PHP Mathematical Calculation Skills Summary", "PHP Array" Operation Techniques Encyclopedia, "PHP string (String) Usage summary, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage Summary", and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

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.