我创建了一个将表情符号短名称转换为图像的函数,但我不知道如何从字符串中获取表情符号短名称,以便该函数可以将它们转换为表情符号图像。
$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
一个简单的解决方案是使用
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]);