使用正则表达式从一段文字中提取URL
PHP使用正则表达式从一段文字中提取URL
现有一段文字如“小猪是吃什么东要这么肥的http://c.com/dkae知道怎么提取吗?”
我想要提取到http://c.com/dkaeaa
请给我点思路
------解决方案--------------------
- PHP code
$str = '小猪是吃什么东要这么肥的http://c.com/dkae知道怎么提取吗?';
preg_match_all('/https?://[w-.%#?/\]+/i', $str, $matches);
print_r($matches);
/**
输出结果:
Array ( [0] => Array ( [0] => http://c.com/dkae ) )
*/ <div class="clear">
</div>









