简体   繁体   中英

htmlentities content that has HTML

I'm trying to support multiple languages on my site. Some of the content that needs translating will have entity references like Ç . I could use htmlentities to convert that into a à . However, what if I need to translate a string that has mark up:

"<p>Hello, <a href="">world with Ç</a></p>"

If I use htmlentities , the < and > would be converted, too. I don't want to break down the string into tags and non-tag parts, then apply htmlentities only to the non-tag parts. That'll be too messy and tedious.

A work around posted here

Pass your string to the following function and work with the returned string.

  function unicode_escape_sequences($str){
      $working = json_encode($str);
      $working = preg_replace('/\\\u([0-9a-z]{4})/', '&#x$1;', $working);
      return json_decode($working);
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM