将表情符号添加到评论但不起作用

时间:2013-03-25 11:01:18

标签: php

我一直在尝试在评论中添加表情符号,但它不起作用,我不知道为什么。

Parse error: syntax error, unexpected T_STRING in /home/content/---------------------------/cdn/postdisplay.php on line 1

包含并加载以显示评论的完整php。

<?php
function smiliess($text) {
        $smilies = array(
            '>:('        =>  '<img src="image/icon/angry.png" alt="angry" class="icon_smile1" />',
            '(angry)'    =>  '<img src="image/icon/angry.png" alt="angry" class="icon_smile2" />',
            '(Angry)'    =>  '<img src="image/icon/angry.png" alt="angry" class="icon_smile3" />',
            '(ANGRY)'    =>  '<img src="image/icon/angry.png" alt="angry" class="icon_smile4" />',
            'B|'         =>  '<img src="image/icon/cool.png" alt="cool" class="icon_smile5" />',
            '(cool)'     =>  '<img src="image/icon/cool.png" alt="cool" class="icon_smile6" />',
            '(Cool)'     =>  '<img src="image/icon/cool.png" alt="cool" class="icon_smile7" />',
            '(COOL)'     =>  '<img src="image/icon/cool.png" alt="cool" class="icon_smile8" />',    
            // more smiley
        );  
    foreach ($smilies as $search => $replace)
        $text = preg_replace("#(?<=\s|^)" . preg_quote($search) . "#", $replace, $text);
    return $text;
}
$CheckQuery = mysql_query("SELECT * FROM t_comment WHERE got='$user->id' ORDER BY `id` DESC LIMIT 0 , 20");
while($row = mysql_fetch_assoc($CheckQuery))
{
    $toolsp = new UserTools();
    $post = $toolsp->get($row['send_id']);  
    $yourText = $row['content'];
    $yourdisplay = smiliess( $yourText );
    echo '<div class="mycomment">
        <div id="postpic">
            <img id="profile_pic" width="50px" height="150px" src="' . $post->image . '" class="" />
        </div>
        <div class="mycommentpost">                     
            <a class="postername" href="profile.php?userID=' . $post->id . '">' . $post->fname . ' ' . $post->lname . ': </a><br />
            ' . $yourdisplay . '
        </div>
    </div>';
}
?>

当我从php中删除表情符号时,它工作正常。

2 个答案:

答案 0 :(得分:2)

您在声明数组时调用了数组$smilies,但在foreach循环中将其作为$smiles调用。

答案 1 :(得分:2)

你有;删除它

while($row = mysql_fetch_assoc($CheckQuery));
                                            ^

并更改您的查询

$CheckQuery = mysql_query("SELECT * FROM t_comment WHERE got='" . $user->id . "' ORDER BY `id` DESC LIMIT 0 , 20");