“无效的“..”-范围,“..”左侧没有字符”调用trim()时出错
假设我有 $url="../folder/file"
并且我想查找并删除 ../
部分。
我正在使用 trim()
……
$url = trim($url,"../");
但它给了我一个警告:
警告:trim() [function.trim]:无效的“..”范围,上一行“..”左侧没有字符
我做错了什么?
Let's say I have $url="../folder/file"
and I want to find and remove the ../
part.
I'm using trim()
…
$url = trim($url,"../");
… but it gives me a warning:
Warning: trim() [function.trim]: Invalid '..'-range, no character to the left of '..' on line above
What I did wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你做错的是没有阅读手册:
what you did wrong was fail to read the manual:
你可以使用 ltrim
或
you can use ltrim
or
php.net/trim 的修剪函数中有一个特殊的语法,允许您指定一个范围,即解释器认为您正在做什么,因为“..”
修剪的第二个参数应该是一个将被删除的字符串,因此您不必放置“.”。两次。
There is a special syntax in the trim function from php.net/trim that allows you to specify a range, which is what the interpreter believes you are doing because of the '..'
The second argument to trim should be a string of characters that would be stripped, so you should not have to put the '.' twice.
修剪函数的第二个参数指定要删除的字符列表,而不是多字符字符串。该函数将“..”解释为指定字符范围的运算符(如 a..z 或 1..5)。您可以通过多种方式去掉“../”,但一个简单的方法是:
The second argument to the trim function specifies a list of characters to be stripped, not a multi-character string. The function interprets '..' as an operator specifying a range of characters (like a..z or 1..5). You can strip out the '../' in a number of ways, but one easy one is this:
我在 php.net 上的修剪页面的底部评论中找到了这个函数,它似乎可以做你想要的
I found this function in bottom comments of the trim page on php.net that seem to do what you want