因此,当用户在描述中输入时:D显示正确的笑脸图像,但当他进入编辑模式时,显示img标签。我需要显示:D而不是img标签。这是整个代码:
$descr="some text :D";
$chars=array(":D", "^_^", ":P", ":(", ":)", "<3");
$icons=array("<img src='css/s/d.png' title='Happy' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/donja.png' title='Very happy' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/tong.png' title='Tongue' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/sad.png' title='Sad' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/gornja.png' title='Smile' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/heart.png' title='heart' width='20px' height='20px' style='margin-bottom:-2px;'>"
);
$ades = str_replace($chars,$icons,$descr);
<div id="bio-data"> ///normal display mode
<i><?php echo $ades; ?></i>
</div>
<textarea id='ebio-datat' placeholder="Tell somehting about yourself" maxlength=300> ///edit mode
<?php echo $ades; ?>
</textarea>
答案 0 :(得分:3)
简单地回复$ descr而不是$ ades。
所以php:
<?php
$descr="some text :D";
$chars=array(":D", "^_^", ":P", ":(", ":)", "<3");
$icons=array("<img src='css/s/d.png' title='Happy' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/donja.png' title='Very happy' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/tong.png' title='Tongue' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/sad.png' title='Sad' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/gornja.png' title='Smile' width='20px' height='20px' style='margin-bottom:-2px;'>"
,"<img src='css/s/heart.png' title='heart' width='20px' height='20px' style='margin-bottom:-2px;'>"
);
$ades = str_replace($chars,$icons,$descr);?>
普通模式:
<div id="bio-data"> ///normal display mode
<i><?php echo $ades; ?></i>
</div>
编辑模式:
<textarea id='ebio-datat' placeholder="Tell somehting about yourself" maxlength=300> ///edit mode
<?php echo $descr; ?>
</textarea>
答案 1 :(得分:0)
两个选项:
echo str_replace($icons,$chars,$descr); //option 1
echo $descr; //option 2
我会选择2。
请参阅键盘链接http://codepad.org/StKRtPS6