doutuo1939 2011-05-16 17:45
浏览 31
已采纳

str_replace不能正常运行PHP

I've got two strings that are lines pulled from a file. I'm trying to first strip them of their tags (like ) by doing a str_replace and replacing them with a space. Unfortunately, this doesn't seem to be working because when I echo out the results in the form I still see the tags.

Any ideas?

# Trim the title and description of their tags. Keep only text.
$title_new = $file_lines[$title_line];
str_replace("<title>"," ", $title_new);
str_replace("</title>"," ", $title_new);

$desc_new = $file_lines[$desc_line];
str_replace("<description>"," ", $desc_new);
str_replace("</description>"," ", $desc_new);

# Echo out the HTML form
echo "<form action=\"rewrite.php\" method=\"post\">";
echo "Title: <input type=\"text\" name=\"new_title\" size=\"84\" value=\"".$title_new."\">";
echo "</input>";

echo "<br>Article Body:<br>";
echo "<textarea rows=\"20\" cols=\"100\" wrap=\"hard\" name=\"new_desc\">".$desc_new."</textarea><br>";

echo "<input type=\"hidden\" name=\"title_line\" value=\"".$title_line."\">";
echo "<input type=\"hidden\" name=\"title_old\" value=\"".$file_lines[$title_line]."\">";
echo "<input type=\"hidden\" name=\"desc_line\" value=\"".$desc_line."\">";
echo "<input type=\"hidden\" name=\"desc_old\" value=\"".$file_lines[$desc_line]."\">";

echo "<input type=\"submit\" value=\"Modify\" name=\"new_submit\">";
  • 写回答

5条回答 默认 最新

  • douqiao8032 2011-05-16 17:49
    关注
     $title_new = str_replace(array("<title>", "</title>")," ", $file_lines[$title_line]);
     $desc_new = str_replace(array("<description>","</description>")," ", $file_lines[$desc_line]);
    

    Or use

    strip_tags

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入