cau*_*tic 22 php string replace converters
我尝试了一些很长的方法,但我认为我做错了.
这是我的代码
<?php print strtolower($blob); ?>
Run Code Online (Sandbox Code Playgroud)
这使得$blob小写,但另外我需要$blob删除任何空格并用短划线(-)替换.
我尝试了这个,但它没有用
<?php print (str_replace(' ', '-', $string)strtolower($blob)); ?>
Run Code Online (Sandbox Code Playgroud)
我能在一行中完成这一切吗?
Ale*_*ara 51
是的,只需传递返回值strtolower($blob)作为str_replace(你所拥有的$string)的第三个参数.
<?php print (str_replace(' ', '-', strtolower($blob))); ?>
Run Code Online (Sandbox Code Playgroud)
str_replace
Run Code Online (Sandbox Code Playgroud)<?php $str = 'Convert spaces to dash and LowerCase with PHP'; echo str_replace(' ', '-', strtolower($str)); // return: convert-spaces-to-dash-and-lowercase-with-php
换行
Run Code Online (Sandbox Code Playgroud)$str = 'Convert spaces to dash and LowerCase with PHP'; echo wordwrap(strtolower($str), 1, '-', 0); // return: convert-spaces-to-dash-and-lowercase-with-php
| 归档时间: |
|
| 查看次数: |
30537 次 |
| 最近记录: |