How to detect emoji in plain text with PHP Preg_Match? REGULAR [E-XX]

23
April 16, 2019, at 11:00 AM

I want to change the expressions in the form [E-01] - [E-02] - [E-03] - [E-04] ... to <img src = "E-XX.png">. How can I do it with PHP preg_match or in a different way?

$message = "Hello [E-02] World [E-01]";
// output text
Hello <img src="E-02.png"> World <img src="E-01.png">
Answer 1
function emoji($message){
            for($e=1; $e <= 60; $e++){
                $e    = (($e < 10) ? '0' . $e : $e);
                $name = 'E-' . $e;
                $message = str_replace('[' . $name . ']', ' <img src="/assets/images/emoji/' . $name. '.png" height="20" width="20" /> ', $message);
            }
            return $message;
        }
Answer 2

Preg_replace is your friend:

$message = "Hello [E-02] World [E-01]";
$replaced = preg_replace('/\[(E-\d\d)\]/', '<img src="/assets/images/emoji/$1.png" height="20" width="20" />', $message);
echo $replaced;

Output:

Hello <img src="/assets/images/emoji/E-02.png" height="20" width="20" /> World <img src="/assets/images/emoji/E-01.png" height="20" width="20" />
READ ALSO
Create/Delete Space seperated folder names

Create/Delete Space seperated folder names

When I try to create a folder whose name is seperated by spaces it only takes the first word and ignores the second oneHow do I solve this? I am writing with php to a dovecot sever

25
Serverload using own postfix with mail() vs phpmailer with external smtp

Serverload using own postfix with mail() vs phpmailer with external smtp

I got a smaller VPS server at the moment ~20%-30% avg load 3 websitesClients need to send emails for order, registration, invoices and newsletter

36