0

I don't know if this question has been already asked! It really seems to be new! I found something similar here, but it is for Java, not PHP.

Here follows my problem. On the client-side, I'm using TinyMCE to get a long text. On the server-side, I extract the first n words from that string for listing purpose.

In particular, the string returned contains HTML code, that I remove by using the PHP strip_tags() function, and it also contains ASCII characters (e.g.   for spaces).

Is there any PHP function that automatically convert all the ASCII contained in a string or capable to detect all the ASCII code in a string?

In the first case all would be easy; in the latter I should find the ASCII and then replace it with the chr() function.

Community
  • 1
  • 1
JeanValjean
  • 17,172
  • 23
  • 113
  • 157

1 Answers1

1

Check the function html_entity_decode()

From the documentation :

html_entity_decode() is the opposite of htmlentities() in that it converts all HTML entities in the string to their applicable characters.

koopajah
  • 23,792
  • 9
  • 78
  • 104
  • Does it returns a string with "-" as separator? – JeanValjean Dec 05 '12 at 08:55
  • 1
    Why would it? It replaces html centities to the corresponding character. ` ` becomes a space, `&` becomes &, etc. – koopajah Dec 05 '12 at 08:57
  • Sorry! My question was related to [this](http://stackoverflow.com/questions/7530238/convert-ascii-and-utf-8-to-non-special-characters-with-one-function) accepted answer. The author shown that the result was the string with the words separated by "-". Thanks! Your answer will be accepted! – JeanValjean Dec 05 '12 at 08:59