使用自定义功能将表情符号短名称转换为图像

问题描述 投票:0回答:1

我创建了一个将表情符号短名称转换为图像的函数,但我不知道如何从字符串中获取表情符号短名称,以便该函数可以将它们转换为表情符号图像。

$field_from_db  = ':slight_smile:';
$shortcode_replace = shortcode_replace();
$shortname = $shortcode_replace[$field_from_db]; This code search in shortcode fucntion and replaces it with unicode to get cdn image 
$shortname = $shortname[0];


echo convertImage($shortname); after we got unicode for cdn predesigned in the shortcodes function it returns back with the image url 

现在我很困惑它如何从字符串转换

$field_from_db  = 'Hello How are you :slight_smile::joy:';
//Here we have a string so how do i convert all short names to emoji using the function i created 
php text replace emojione
1个回答
0
投票

一个简单的解决方案是使用

preg_match_all
函数来实现这一点:

<?php

$string  = 'Hello How are you :slight_smile::joy:';

$regex = "/:([a-zA-Z0-9_]*):/";
preg_match_all($regex, $string, $matches);

print_r($matches[0]);

演示:https://3v4l.org/ro1m3

© www.soinside.com 2019 - 2024. All rights reserved.