How to remove content from url after question mark. preg_match or preg_replace?

为君一笑 提交于 2019-12-02 01:05:30

Even easier: use explode():

list($uri,) = explode('?', 'http://somesite.com/uploaded/images/8.jpg?m=eSuQKgaaaa&mh=t0i7nVhjZleTJ5Ih');

update

Or simpler yet use strtok and trim:

$uri = trim(strtok('http://somesite.com/uploaded/images/8.jpg?m=eSuQKgaaaa&mh=t0i7nVhjZleTJ5Ih', '?'));

Normally you would use parse_url() for working with URLs but in a case like this, using explode() is simpler to use and serve's your purpose.

In a much easier way it could be:

$iWantThisURL = substr($curr_url(), 0, stripos($curr_url, '?'));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!