如何在 PHP 代码中插入表情符号?

发布于 2024-08-31 09:29:31 字数 63 浏览 3 评论 0原文

我有一个用 PHP 语言编写的 Shoutout Box。它没有 Smileys 支持。如何在其中插入笑脸支持?

I have a Shoutout Box written in PHP language.It doesnt have Smileys Support. How Can I Insert Smiley Support in it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

长安忆 2024-09-07 09:29:32

一些当时对我有用的 PHP ;)

function Smilify(&$subject)
{
    $smilies = array(
        ':|'  => 'mellow',
        ':-|' => 'mellow',
        ':-o' => 'ohmy',
        ':-O' => 'ohmy',
        ':o'  => 'ohmy',
        ':O'  => 'ohmy',
        ';)'  => 'wink',
        ';-)' => 'wink',
        ':p'  => 'tongue',
        ':-p' => 'tongue',
        ':P'  => 'tongue',
        ':-P' => 'tongue',
        ':D'  => 'biggrin',
        ':-D' => 'biggrin',
        '8)'  => 'cool',
        '8-)' => 'cool',
        ':)'  => 'smile',
        ':-)' => 'smile',
        ':('  => 'sad',
        ':-(' => 'sad',
    );

    $sizes = array(
        'biggrin' => 18,
        'cool' => 20,
        'haha' => 20,
        'mellow' => 20,
        'ohmy' => 20,
        'sad' => 20,
        'smile' => 18,
        'tongue' => 20,
        'wink' => 20,
    );

    $replace = array();
    foreach ($smilies as $smiley => $imgName)
    {
        $size = $sizes[$imgName];
        array_push($replace, '<img src="imgs/'.$imgName.'.gif" alt="'.$smiley.'" width="'.$size.'" height="'.$size.'" />');
    }
    $subject = str_replace(array_keys($smilies), $replace, $subject);
}

在此处输入图像描述

Some PHP that worked for me back in the day ;)

function Smilify(&$subject)
{
    $smilies = array(
        ':|'  => 'mellow',
        ':-|' => 'mellow',
        ':-o' => 'ohmy',
        ':-O' => 'ohmy',
        ':o'  => 'ohmy',
        ':O'  => 'ohmy',
        ';)'  => 'wink',
        ';-)' => 'wink',
        ':p'  => 'tongue',
        ':-p' => 'tongue',
        ':P'  => 'tongue',
        ':-P' => 'tongue',
        ':D'  => 'biggrin',
        ':-D' => 'biggrin',
        '8)'  => 'cool',
        '8-)' => 'cool',
        ':)'  => 'smile',
        ':-)' => 'smile',
        ':('  => 'sad',
        ':-(' => 'sad',
    );

    $sizes = array(
        'biggrin' => 18,
        'cool' => 20,
        'haha' => 20,
        'mellow' => 20,
        'ohmy' => 20,
        'sad' => 20,
        'smile' => 18,
        'tongue' => 20,
        'wink' => 20,
    );

    $replace = array();
    foreach ($smilies as $smiley => $imgName)
    {
        $size = $sizes[$imgName];
        array_push($replace, '<img src="imgs/'.$imgName.'.gif" alt="'.$smiley.'" width="'.$size.'" height="'.$size.'" />');
    }
    $subject = str_replace(array_keys($smilies), $replace, $subject);
}

enter image description here

我的黑色迷你裙 2024-09-07 09:29:32

您可以简单地执行以下操作:

<?php
echo str_replace(';)', '<img src="path/to/smile_image.gif" title=";)"/>', $message);
?>

You can simply do:

<?php
echo str_replace(';)', '<img src="path/to/smile_image.gif" title=";)"/>', $message);
?>
秋叶绚丽 2024-09-07 09:29:32

我发现了这个,它对我有帮助..
http://os.alfajango.com/css-emoticons/

I found this and it helped me..
http://os.alfajango.com/css-emoticons/

江城子 2024-09-07 09:29:32

我会使用 javascript 来检查添加的喊声是否有“:-)”之类的组合,并将其替换为笑脸图像

I would use javascript to check added shouts for combinations like ':-)' and replace them with an image of an smiley

-黛色若梦 2024-09-07 09:29:32

使用传递字符串创建函数。并替换为图像中的一些文本,如下所示。

function parseString($string ) {
$my_smilies = array(
    ':aln' => '<img src="images/alien1.png" alt="" />',
    ':thk' => '<img src="images/annoyed.png" alt="" />',
    ':ang' => '<img src="images/angel.png" alt="" />',
    ':slp<' => '<img src="images/zzz.png" alt="" />',
    ':blnk' => '<img src="images/blanco.png" alt="" />',
    ':zip' => '<img src="images/zip_it.png" alt="" />',
    ':bor' => '<img src="images/boring.png" alt="" />',

);

return str_replace( array_keys($my_smilies), array_values($my_smilies), $string);

}

Create function with pass string. And replace with the some text to image like below.

function parseString($string ) {
$my_smilies = array(
    ':aln' => '<img src="images/alien1.png" alt="" />',
    ':thk' => '<img src="images/annoyed.png" alt="" />',
    ':ang' => '<img src="images/angel.png" alt="" />',
    ':slp<' => '<img src="images/zzz.png" alt="" />',
    ':blnk' => '<img src="images/blanco.png" alt="" />',
    ':zip' => '<img src="images/zip_it.png" alt="" />',
    ':bor' => '<img src="images/boring.png" alt="" />',

);

return str_replace( array_keys($my_smilies), array_values($my_smilies), $string);

}

后知后觉 2024-09-07 09:29:32

最好使用笑脸代码,无需使用替换功能。

https://www.w3schools.com/charsets/ref_emoji_smileys.asp

例如:< code>

我将显示 😀

结果:

我将显示

Better to use smiley codes, no need to use replace functions.

https://www.w3schools.com/charsets/ref_emoji_smileys.asp

eg: <p>I will display 😀</p>

result:

I will display ????

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文