小编use*_*871的帖子

使用PHP替换文本文件中的字符串

我需要打开一个文本文件并替换一个字符串.我需要这个

Old String: <span id="$msgid" style="display: block;">
New String: <span id="$msgid" style="display: none;">
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止,但除了额外的空格之外,我没有看到文本文件有任何变化.

$msgid = $_GET['msgid'];

$oldMessage = "";
$deletedFormat = "";

// Read the entire string
$str = implode("\n", file('msghistory.txt'));

$fp = fopen('msghistory.txt', 'w');

// Replace something in the file string - this is a VERY simple example
$str = str_replace("$oldMessage", "$deletedFormat", $str);

fwrite($fp, $str, strlen($str));
fclose($fp);
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

php text replace file

32
推荐指数
3
解决办法
9万
查看次数

在PHP中使用变量

请告诉我我做错了什么,当php文件执行时将实际文件夹保存为"$ name"而不是Peter.我究竟做错了什么?

这是我的代码:

$name = "Peter";
copy_directory('you/','dir/$name');
Run Code Online (Sandbox Code Playgroud)

php variables

0
推荐指数
1
解决办法
115
查看次数

PHP减法

我必须从另一个数字中减去一个数字,但是脚本必须验证这是可能的,而不给出负数.

例如,客户的信用额度为5.00美元.他们想要购买20美元,现在他们只需要15美元,所以他们无法购买.现在它必须将它们重定向到一个页面(Insuffient funds).

php logic redirect subtraction

0
推荐指数
1
解决办法
353
查看次数

标签 统计

php ×3

file ×1

logic ×1

redirect ×1

replace ×1

subtraction ×1

text ×1

variables ×1