Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 留言簿中回复的多个微笑_Php_Javascript_Database_Forms - Fatal编程技术网

Php 留言簿中回复的多个微笑

Php 留言簿中回复的多个微笑,php,javascript,database,forms,Php,Javascript,Database,Forms,我在留言簿中添加了笑脸以回复评论 当我想用以下代码回复1条评论时,它工作正常: if (isset($_GET['action']) && $_GET["action"] == "reply" ) { $commentrpl = substr(stripEmails(strip_tags($_POST["txtreply"])), 0, 250); $rpl_arr = array( "O:-)" => "<img src=\"".D

我在留言簿中添加了笑脸以回复评论

当我想用以下代码回复1条评论时,它工作正常:

if (isset($_GET['action']) && $_GET["action"] == "reply" ) {
    $commentrpl = substr(stripEmails(strip_tags($_POST["txtreply"])), 0, 250);

    $rpl_arr = array(
        "O:-)" => "<img src=\"".DOC_ROOT."images/sml/aa.gif\"\/>",
        ":-)"  => "<img src=\"".DOC_ROOT."images/sml/ab.gif\"\/>",
        ":-("  => "<img src=\"".DOC_ROOT."images/sml/ac.gif\"\/>",
    );

    $commentrpl  = strtr($commentrpl, $rpl_arr);
    $osDB->query('UPDATE ! SET reply = ? WHERE id = ?', array( 
        COMMENTS_TABLE, 
        $commentrpl, 
        $_REQUEST["commentid"] 
    ));
}
表格:


使用str\u替换为以下内容,而不是strstr:

$smiles = array(
    ':-)' => '<img ...>',
    ...
);

$comment = str_replace(array_keys($smiles), array_values($smiles), $comment);
$smiles=array(
':-)' => '',
...
);
$comment=str_replace(数组_键($smiles)、数组_值($smiles)、$comment);

除此之外,最好在显示注释/回复时进行替换,而不是将其保存到数据库中

“更多评论”是什么意思?我在你的代码里什么地方都看不到。顺便说一句,如果没有任何上下文,JS代码段是无用的。它的意思是作为留言簿。用户可以添加评论,接收用户可以回复该评论。只要没有回复,就会有一个文本区和提交按钮(这很好)。如果回复,则不只是文本。因此,如果用户收到多条评论,则会有多个文本区域用于回复。每个文本区域都附加了一组笑脸。微笑只有在有1条评论和1条未回复的回复时才起作用。一旦有多个未答复的答复,只有文本输入起作用。不能有多个ID相同的元素(在您的案例中为“txtreply”)
<form name="reply" method="post" action="showprofile.php?id={$profileid}&amp;commentid={$item.id}&amp;action=reply">
    <textarea id="txtreply" name="txtreply" cols="50" rows="5"></textarea>
    <img src="images/sml/aa.gif" onclick="smile4('O:-)');" alt="O:-)">
    <input type="submit" name="btnAdd" value="{lang mkey='send'}" /> 
</form>
$smiles = array(
    ':-)' => '<img ...>',
    ...
);

$comment = str_replace(array_keys($smiles), array_values($smiles), $comment);