我怎样才能删除动态进入锚标记的白色 space
How can i remove the white space dynamically getting in anchor tag
我正在通过
了解我们
<?php echo ($contents->title); ?>.
但我想将其转换为 About_us。我怎样才能做到这一点?单击该锚点后,它在 URL 中显示 About us
,但我想删除它们之间的 space 或将其更改为 About_us。
<a class="smoothscroll" href="#<?php echo ($contents->title); ?>" scroll-to="#para_1">
您可以使用 str_replace
将字符串中的所有空格替换为下划线,如下所示:
<?php $contents->title = str_replace(' ','_',$contents->title); ?>
如果 $contents->title
包含 About Us
那么上面的代码会将 About Us
替换为 About_Us
我正在通过
了解我们<?php echo ($contents->title); ?>.
但我想将其转换为 About_us。我怎样才能做到这一点?单击该锚点后,它在 URL 中显示 About us
,但我想删除它们之间的 space 或将其更改为 About_us。
<a class="smoothscroll" href="#<?php echo ($contents->title); ?>" scroll-to="#para_1">
您可以使用 str_replace
将字符串中的所有空格替换为下划线,如下所示:
<?php $contents->title = str_replace(' ','_',$contents->title); ?>
如果 $contents->title
包含 About Us
那么上面的代码会将 About Us
替换为 About_Us