dougou8573 2015-02-03 07:41
浏览 37

如何使用PHP在PHP文件中查找和编辑特定数据

So in my script I copy a PHP file used as a model and/or template file. But i can not figure out how to find the data that needs to be edited, and editing it. I don't want to truncate the whole file just need to edit a line of text in the file and save it. Below is what I have so far.

$file = '../postback/postback.php';
$pbac = '../postback/'.md5($affn).'.php';
copy($file, $pbac);

$files = file_get_contents($pbac);

// Stick the new IP just before the closing </files>
$new_files = str_replace('//ADD NAME HERE//', "//ADD NAME HERE//
\$name ='".$affn."';", $files);  

// And write the new string back to the file
file_put_contents($pbac, $new_files);
$pback = '/postback/'.md5($affn).'.php';

As you can see I have the code to do it. But it is not working. I don't know what i am doing wrong. perhaps someone else looking at it can point out the problem.

The file is copied. There are no errors displaying or listing in my error log. There are no edits being made though. //ADD NAME HERE// Is on a line by itself.

  • 写回答

1条回答 默认 最新

  • duanguane1670 2015-02-03 10:48
    关注

    A semi-colon was missing for the $affn variable.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度