PHP Regular expression store display expression character method

Source: Internet
Author: User

In interaction with the user, the front end of the long text in theory allows the user to use the expression, but the current end of the expression to the background interface, due to some of the data coding restrictions, there is no way to save such data.

The method I use here is to use the emoticons in the regular transformation text and then read from the database, and then do a reverse regularization.

"Note: After the success of emoticons, the pro-test in the micro-letter, browser, and mobile phone side, will automatically match the current expression character"

Put 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 long text content after processing
*
* @param $content
* @return Mixed
*/
Public Function GetContent ($content) {
Return Preg_replace_callback ('/@e (. { 6}==)/', function ($r) {return Base64_decode ($r [1]);}, $content);
}

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.