Home  >  Article  >  Backend Development  >  应用正则表达式从一段文字中提取URL

应用正则表达式从一段文字中提取URL

WBOY
WBOYOriginal
2016-06-13 13:15:12892browse

使用正则表达式从一段文字中提取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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn