我正在尝试删除网址字符串中'.html'及其后面的所有内容。当前(失败的)代码如下:
$input = 'http://example.com/somepage.html?foo=bar&baz=x';
$result = preg_replace("/(.html)[^.html]+$/i",'',$input);
期望的结果:
value of $result is 'http://example.com/somepage'
以下是一些与输入 $input 对应的相同结果 $result 的其他示例:
http://example.com/somepage
http://example.com/somepage.html
http://example.com/somepage.html?url=http://example.com/index.html