php trim(),效果不佳 [英] php trim(), work poorly
本文介绍了php trim(),效果不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从页面 url www 中剪切.使用 php trim() 函数.但是这个函数截了首字母,为什么呢?
I need cut from page url www. using php trim() function. But this function cut and first letter, why?
$domain = parse_url('http://wordpresas.com/page/1');
$domain['host'] = trim($domain['host'], 'www.');
pr($domain['host']); //ordpresas.com
推荐答案
正如其他人所说,trim()
的第二个参数包含 被修剪的字符列表.
As other have stated the second parameter of trim()
contains a list of characters which get trimmed.
但是你可以使用 preg_replace()
为此.这将确保只有 www.
将被剥离,如果字符串以它开头.
However you can use preg_replace()
for this. This will make sure only www.
will be stripped if the string starts with it.
preg_replace('/^www./', '', $domain['host']);
这篇关于php trim(),效果不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文