Find a regular expression and replace the emoticon of a rule with an emoticon icon (<img> emoticon)

Source: Internet
Author: User
Find a regular expression, replace the emoticon of a rule with the expression icon (& lt; img & gt; expression), and find a regular expression, replace a regular emoticons with emoticons (emoticons)

[Happy] is replaced by (the naming rules for images in Chinese are not standard ?)

In fact, it is better to use JS for comparison.


Reply to discussion (solution)

$ Str = '[happy] emoticon image ';
Echo preg_replace ('/\ [(. *) \]/', "", $ str );

This year, everything is regular...
It is not wise to use a Chinese name as a file name.

Function replaceStr ($ str ){
$ Str = substr ($ str, strpos ($ str, '[') + 1, strlen ($ str)-2 );
Return "";
}

How is the efficiency of replacing the entire page?

$ Str = '[happy] emoticon image ';
Echo preg_replace ('/\ [(. *) \]/', "", $ str );

It should be acceptable.

I found a JQ plug-in on the Internet and replaced it on the client. for English emojis such as [happy], they can be replaced, but once changed to [happy] Chinese emojis, they won't work. well, I also feel that the file name in Chinese is not good.

// jQuery Plugins: On/Off Emtions var __emotion__cache = false;jQuery.fn.emotions = function() {    var aEmotion = new Array();        aEmotion[21] = new Array('[happy]','\\[happy\\]');        __emotion__cache = true;    this.each(function() {        str = $(this).html();        for(iEM in aEmotion){            reg =  new RegExp(aEmotion[iEM][1],"ig");            str = str.replace(reg,'');        }        $(this).html(str);    });};jQuery.fn.unemotions = function(){    __emotion__cache = false;    $('.plugin_emotion').each(function(){        $(this).html(decodeURIComponent(this.title));                                       });}

This year, everything is regular...
It is not wise to use a Chinese name as a file name.

Function replaceStr ($ str ){
$ Str = substr ($ str, strpos ($ str, '[') + 1, strlen ($ str)-2 );
Return "";
}

Chinese file names are not compatible with various types of pain points...

Check whether there is an error message.

Alert (str );
Check whether it is replaced.


It is estimated that the image name is a Chinese name. Change to English

The JQ plug-in Replaces [face] with 0.png00001.png00002.png.
But it's strange to change face to Chinese...

Check whether there is an error message.

Alert (str );
Check whether it is replaced.


It is estimated that the image name is a Chinese name. Change to English

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.