我尝试将str_replace和preg_replace写成'\',但两者都不起作用
$old[0]= '\item'
$new='';
$fread = str_replace($old, $new, $fread);
它只从字符串中删除'item'。
$fread=preg_replace('/\\item/', "", $fread);
它也只从$ fread中删除'item'。
答案 0 :(得分:1)
<?php
$fread = 'is this "\item" gone yet?';
$old = '\\item'; //OR [ 'item', '\\'];
$new='';
echo str_replace($old, $new, $fread) ;
答案 1 :(得分:1)
试试这个
$fread = 'is this \item gone yet? \"hmmm\". it\'s a ball.';
$search= ["\\", "item"]; // use double quote for backslash and escape with backslash
$replace=['', ''];
$fread = str_replace($search, $replace, $fread);
echo $fread; // is this gone yet? "hmmm". it's a ball.