无法获取str_replace()来删除PHP字符串中的空格

问题描述:

我得到一个PHP字符串,需要将空格删除.我使用了以下代码,但是当我回显$classname时,它仅显示字符串,其中仍带有空格.

Hi, I am getting a PHP string which I need to strip the spaces out of. I have used the following code but when I echo $classname it just displays the string still with the spaces in it.

   <?php
     $fieldname = the_sub_field('venue_title');
     $classname = str_replace(' ', '', $fieldname);
     echo $classname;
   ?>

尝试为正则表达式模式添加 u 参数,因为字符串可以具有UTF-8编码:
>

Try to add u-parameter for regex-pattern, because a string can have UTF-8 encoding:

$classname  =  preg_replace('/\s+/u', '', $fieldname);