Php storage method for displaying emoticon characters [regular expression conversion]-php Tutorial

Source: Internet
Author: User
Php storage expression character display method [regular expression conversion] in interaction with users, the front-end long text theoretically allows users to use the expression, but when the front-end uploads the expression to the background interface, due to the encoding restrictions of some data, there is no way to save such data.

The method I use here is to convert the emoticons in text using regular expressions, read them from the database, and perform a reverse regular expression.

[Note: After the emoticon is successfully escaped, it will automatically match the current emoticon in the browser]

Paste the code below

/*** Set long text content ** @ param $ content * @ return mixed */public function setContent ($ content) {return preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return' @ e '. base64_encode ($ r [0]) ;}, $ content );} /*** get the processed long text content ** @ param $ content * @ return mixed */public function getContent ($ content) {return preg_replace_callback ('/@ E (. {6 }=)/', function ($ r) {return base64_decode ($ r [1]) ;}, $ content );}

Permanent Address: http://blog.it985.com/16082.html

This article is from the IT985 blog. please indicate the source and relevant links when reprinting.

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.