Phphtml entity character conversion

Source: Internet
Author: User
Phphtml entity character conversion what functions can php convert html entity symbol 'é?

Php has tried several functions.


Reply to discussion (solution)

I don't know how you do it.

First, let's give you a list of HTML entities supported by php.
Foreach (get_html_translation_table (HTML_ENTITIES) as $ k => $ v ){
Echo ord ($ k). '=>'. $ v. PHP_EOL;
}

Then you can do it yourself.

Agree upstairs

It seems that this symbol is supported. which function should be used for conversion?

I don't know how you do it.

First, let's give you a list of HTML entities supported by php.
Foreach (get_html_translation_table (HTML_ENTITIES) as $ k => $ v ){
Echo ord ($ k). '=>'. $ v. PHP_EOL;
}

Then you can do it yourself.

echomb_convert_encoding("é", "UTF-8", "HTML-ENTITIES"); //é

Good. what if there are many such characters in an article that need to be converted? I can't change them one by one. Is there a simpler way?

PHP code

Echo mb_convert_encoding ("& eacute;", "UTF-8", "HTML-ENTITIES ");
// É

Do you want this?

Foreach (get_html_translation_table (HTML_ENTITIES) as $ k => $ v ){
$ Str = str_replace ($ v, mb_convert_encoding ($ v, "GBK", "HTML-ENTITIES"), $ str );
}


Good. what if there are many such characters in an article that need to be converted? I can't change them one by one. Is there a simpler way? Reference reply on the 4th floor:

PHP code

Echo mb_convert_encoding ("& amp; eacute;", "UTF-8", "HTML-ENTITIES ");
// É

Html_entity_decode

$ Text = mb_convert_encoding ($ text, "UTF-8", "HTML-ENTITIES ");

Or you. Solve the problem that has plagued me for a long time. You can fall asleep tonight.

$ Text = mb_convert_encoding ($ text, "UTF-8", "HTML-ENTITIES ");

There is still a problem. The characters are converted clean. However, common characters such as spaces do not work.
For example
$ Str = 'ban "√ "';

$ Str = mb_convert_encoding ($ str, "GBK", "HTML-ENTITIES ");
Echo $ str;

$ Text = mb_convert_encoding ($ text, "UTF-8", "HTML-ENTITIES ");

Html_entity_decode ');

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.