给定输出中的多个 str_replace (PHP)
multiple str_replace in given output (PHP)
PHP 真的很糟糕。学习它。我这里有一个来自抓取数据的输出。数据被抓取并保存在名为 nationalhi 的缓存文件中。在输出中,有一个不需要的“2)”,所以我输入了一个 str_replace 并且它成功地摆脱了它。问题是,还有一个“5)”我想去掉,但每次我尝试组合两个 str 时,它都会破坏代码,因为我做错了什么。有 suggestions/help 吗?非常感谢。
具有一个 str 替换功能的工作代码:
file_put_contents(globalVars::$_cache_dir . "nationalhifour",
str_replace('Low', ' ', $ret_[39]));
两个 STR 替换,不起作用:
file_put_contents(globalVars::$_cache_dir . "nationalhi", str_replace('2)',
' ', str_replace('5)', ' ', $ret_[35]));
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [,
int &$count ] ) If search and replace are arrays, then str_replace()
takes a value from each array and uses them to search and replace on
subject
有关详细信息,请查看 str_replace
这是一个例子
echo str_replace(['1','2','3'],['100','200','300'],'the strings 1 2 3 are replaced successfully ');
// output the strings 100 200 300 are replaced successfully
PHP 真的很糟糕。学习它。我这里有一个来自抓取数据的输出。数据被抓取并保存在名为 nationalhi 的缓存文件中。在输出中,有一个不需要的“2)”,所以我输入了一个 str_replace 并且它成功地摆脱了它。问题是,还有一个“5)”我想去掉,但每次我尝试组合两个 str 时,它都会破坏代码,因为我做错了什么。有 suggestions/help 吗?非常感谢。
具有一个 str 替换功能的工作代码:
file_put_contents(globalVars::$_cache_dir . "nationalhifour",
str_replace('Low', ' ', $ret_[39]));
两个 STR 替换,不起作用:
file_put_contents(globalVars::$_cache_dir . "nationalhi", str_replace('2)',
' ', str_replace('5)', ' ', $ret_[35]));
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) If search and replace are arrays, then str_replace() takes a value from each array and uses them to search and replace on subject
有关详细信息,请查看 str_replace 这是一个例子
echo str_replace(['1','2','3'],['100','200','300'],'the strings 1 2 3 are replaced successfully ');
// output the strings 100 200 300 are replaced successfully