我正在寻找一种从字符串中获取有效网址的方法,例如:
$string = 'http://somesite.com/directory//sites/9/my_forms/3-895a3e/somefilename.jpg|:||:||:||:|19845';
我原来的解决方案是:
preg_match('#^[^:|]*#', str_replace('//', '/', $string), $modifiedPath);
但显然它会从 http:// 中删除一个斜杠,而不是字符串中间的斜杠。
我想要的原始输出是:
http://somesite.com/directory/sites/9/my_forms/3-895a3e/somefilename.jpg
我总是可以先断开字符串的 http 部分,但如果可能的话,我想要一个更优雅的正则表达式解决方案。谢谢。