Friday, 15 May 2015

php - htmlentities and html_entity_decode do not behave as reverse -


I want to shorten a string in a certain amount of characters. This string contains the HTML characters. Notice that I stripped all the html-tags from the string. Now, if there is a special character in the breakpoint, then it should not be broken in the middle of the HT character, but these examples do not work after this, or after:

  // Example 1 $ str = "French france for French and CCLL; AIS"; $ Str = substr ($ str, 0, 27); // $ str in "French French is & amp; c;" // Example 2 $ str = "N Dash & amp; # 8211;"; $ Str = substr ($ str, 0, 25); // $ str include "N dash looks & amp; ##;;  

So I thought that I should convert special characters into one letter, make transcription and then return a single character to special characters. It works in the first instance, but the second is not.

  // Example 1 $ str = "French is French and Frank franc for; ais"; $ Str = html_entity_decode ($ str); $ Str = substr ($ str, 0, 27); $ Str = htmlentities ($ str); // $ str is "French French franca"; // Example 2 $ str = "N Dash & amp; # 8211;"; $ Str = html_entity_decode ($ str); $ Str = substr ($ str, 0, 25); $ Str = htmlentities ($ str); // $ str include "N dash looks & amp; ##;;  

For both examples what should I do, the way I expect them, what should I do?

Homelandat will default your default_charset php.ini value for your encoding uses it. If you are not using characters that support characters that you are changing, then it can not behave as expected. Try it and see if you get different results.

htmlentities ($ str, null, 'utf-8');

html_entity_decode $ Str, null, 'utf-8');

mb_substr ($ str, 0, 25, 'utf-8');


No comments:

Post a Comment