关于rtrim

第9行已经去除了‘&^’字符,第11 行怎么还可以根据'&^' 这个字符来分割的?我理解 不了有两个'&^'字符呀

  • 天蓬老师
  • 天蓬老师    2019-04-12 09:33:271楼

    请把代码贴上来帮你分析

    +0添加回复

  • 回复

    实现留言板功能: 1、writ.php 文件实现字符写入本地文本: ```php <?php //追加方式打开文件 $fp=fopen('message.txt','a'); //设置时间 $time=time(); //得到用户名 $username=trim($_POST['username']); //得到内容 $content=trim($_POST['content']); //组合写入的字符串:内容和用户之间分开,使用$# //行与行之间分开,使用&^ $string=$username.'$#'.$content.'$#'.$time.'&^'; //写入文件 fwrite($fp,$string); //关闭文件 fclose($fp); header('location:index.php'); ?> ``` 2、index.php文件,实现输入内容的前台页面、显示已经留言的内容: ```php <?php //追加方式打开文件 $fp=fopen('message.txt','a'); //设置时间 $time=time(); //得到用户名 $username=trim($_POST['username']); //得到内容 $content=trim($_POST['content']); //组合写入的字符串:内容和用户之间分开,使用$# //行与行之间分开,使用&^ $string=$username.'$#'.$content.'$#'.$time.'&^'; //写入文件 fwrite($fp,$string); //关闭文件 fclose($fp); header('location:index.php'); ?> ``` index.php文件的 `$string = rtrim($string, '&^');` 这个代码不明白,“&^”是一次留言的分界,这里去掉"&^"这个字符了,那下一句`$arr = explode('&^', $string);` 怎么还能使用“&^”这个字符 呢

    潘栋民  作者 · 2019-04-12 09:40:09
    回复

    <?php //追加方式打开文件 $fp=fopen('message.txt','a'); //设置时间 $time=time(); //得到用户名 $username=trim($_POST['username']); //得到内容 $content=trim($_POST['content']); //组合写入的字符串:内容和用户之间分开,使用$# //行与行之间分开,使用&^ $string=$username.'$#'.$content.'$#'.$time.'&^'; //写入文件 fwrite($fp,$string); //关闭文件 fclose($fp); header('location:index.php'); ?>

    潘栋民  作者 · 2019-04-12 09:40:44
    回复

    //m.sbmmt.com/code/1192.html 这个页面的代码。直接贴代码上来格式太乱了,我不知道怎么上传代码好一点

    潘栋民  作者 · 2019-04-12 09:41:52
    回复