PHP preg_replace无法正常工作

PHP preg_replace无法正常工作

问题描述:

okay so i got a script that removes "_" and replaces it with a space " " and it does not work i even used ereg_replace and eregi_replace none worked yet it works backwards( " ","_")

thanks a lot here is the script:

$namefixed = preg_replace("/_/", " ", $name);

and even

$namefixed = preg_replace("_", " ", $name);

好吧所以我得到一个删除“_”的脚本并用空格“”替换它并且它不起作用 我甚至使用了ereg_replace和eregi_replace没有工作但它向后工作(“”,“_”) p>

非常感谢脚本: p>

   $ namefixed = preg_replace(“/ _ /”,“”,$ name); 
  code>  pre> 
 
 

甚至 p>

  $ namefixed = preg_replace(“_”,“”,$ name); 
  code>  pre> 
  div>

No need for regex, just use str_replace().

$namefixed = str_replace("_", " ", $name);

If it only works backwards, then you're replacing spaces with underscores, which can only mean that there aren't any underscores in $name to replace in the first place, or you're searching in the wrong variable...