PHP 删除页面名称正则表达式 - preg_replace
我有这个网址(几个类似的)..
images/image1/image1.jpg
images/images1/images2/image2.jpg
images/images2/images3/images4/image4.jpg
我有这个正则表达式:但我希望它从字符串中删除图像名称:
<?php $imageurlfolder = $pagename1;
$imageurlfolder = preg_replace('/[A-Za-z0-9]+.asp/', '', $pagename1);?>
该字符串看起来像上面的网址 images/images2/images3/images4/< /code> 但没有
image4.jpg
希望你能帮忙
谢谢
I have this url (several similar ones)..
images/image1/image1.jpg
images/images1/images2/image2.jpg
images/images2/images3/images4/image4.jpg
I have this regex: but I want it to strip away the image name from the string:
<?php $imageurlfolder = $pagename1;
$imageurlfolder = preg_replace('/[A-Za-z0-9]+.asp/', '', $pagename1);?>
the string would look like the url's above images/images2/images3/images4/
but without the image4.jpg
hope you can help
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于此特定目的,函数 dirname() 就足够了:
将返回:
For this particular purpose function dirname() would be sufficient:
Would return:
我认为您可以使用 dirname 函数
(来自该页面)
会打印
I think you can use the dirname function
for instance (from that page)
would print
一种非常简单的方法:
它将删除最后一个 / 和字符串末尾之间的所有内容。
编辑:正如许多人指出的那样,您还可以使用 dirname 这可能会更快......
A quite straightforward way to do it:
It will remove everything between the last / and the end of the string.
Edit: as many peopole pointed out, you can also use dirname which might proof faster…