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

WBOY
Release: 2016-06-13 13:15:12
Original
852 people have browsed it

使用正则表达式从一段文字中提取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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!