使用PHP将空格转换为破折号和小写

使用PHP将空格转换为破折号和小写,php,string,replace,converters,Php,String,Replace,Converters,我试过一些很长的方法,但我觉得我做错了什么 这是我的密码 <?php print strtolower($blob); ?> 我能在一行中完成这一切吗?是的,只需将strtolower($blob)的返回值作为stru replace的第三个参数传递(其中有$string) 对于字符串换行,您可以使用专用功能 stru_替换 顺便说一句,在WordPress中,您可以使用带有破折号的清理标题 如何将术语表A-Z转换为术语表A-Z? <?php print (str_repl

我试过一些很长的方法,但我觉得我做错了什么

这是我的密码

<?php print strtolower($blob); ?>

我能在一行中完成这一切吗?

是的,只需将
strtolower($blob)
的返回值作为
stru replace
的第三个参数传递(其中有
$string


对于字符串换行,您可以使用专用功能

stru_替换


顺便说一句,在WordPress中,您可以使用带有破折号的
清理标题


如何将术语表A-Z转换为术语表A-Z?
<?php print (str_replace(' ', '-', $string)strtolower($blob)); ?>
<?php print (str_replace(' ', '-', strtolower($blob))); ?>
<?php

$str = 'Convert spaces to dash and LowerCase with PHP';

echo str_replace(' ', '-', strtolower($str));
// return: convert-spaces-to-dash-and-lowercase-with-php
$str = 'Convert spaces to dash and LowerCase with PHP';

echo wordwrap(strtolower($str), 1, '-', 0);
// return: convert-spaces-to-dash-and-lowercase-with-php