Php 需要预匹配所有链接
我有一根像这样的线:Php 需要预匹配所有链接,php,regex,Php,Regex,我有一根像这样的线: $string = "some text http://dvz.local/index/index/regionId/28 http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php http://192.168.3.192/roadmap_page.php#qwe"; /http:\/\/([^\s]+)/ 需要得到所有的链接 我试过这样做
$string = "some text
http://dvz.local/index/index/regionId/28
http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php
http://192.168.3.192/roadmap_page.php#qwe";
/http:\/\/([^\s]+)/
需要得到所有的链接
我试过这样做:/http:\/\/(.*)[|\s]?/
返回:
array(2) {
[0] =>
array(3) {
[0] =>
string(42) "http://dvz.local/index/index/regionId/28\r\n"
[1] =>
string(77) "http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php\r\n"
[2] =>
string(41) "http://192.168.3.192/roadmap_page.php#qwe"
}
[1] =>
array(3) {
[0] =>
string(34) "dvz.local/index/index/regionId/28\r"
[1] =>
string(69) "stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php\r"
[2] =>
string(34) "192.168.3.192/roadmap_page.php#qwe"
}
}
编辑1:
期望:
试试这个:
$string = "some text
http://dvz.local/index/index/regionId/28
http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php
http://192.168.3.192/roadmap_page.php#qwe";
/http:\/\/([^\s]+)/
试试这个:
$string = "some text
http://dvz.local/index/index/regionId/28
http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php
http://192.168.3.192/roadmap_page.php#qwe";
/http:\/\/([^\s]+)/
试试这个:
preg_match_all('|http://([^\s]*)|', $string, $matches);
var_dump($matches);
试试这个:
preg_match_all('|http://([^\s]*)|', $string, $matches);
var_dump($matches);
来自文本的所有链接
http[s]?[^\s]*来自文本的所有链接
http[s]?[^\s]*许多页面只有到主文档的相对链接(因此没有要解析的http(s):/…),对于这些页面,通过
href
属性进行拆分,可以很好地执行以下操作:
preg_match_all('|href="([^\s]*)"><\/a>|', $html, $output_array);
许多页面只有到主文档的相对链接(因此没有http(s):/…可解析),对于这些页面,通过
href
属性进行拆分,可以很好地执行以下操作:
preg_match_all('|href="([^\s]*)"><\/a>|', $html, $output_array);
$text=preg_replace('/(http[s]?[^\s]*)/,'','$text)$text=preg_replace('/(http[s]?[^\s]*)/',''$text);