如何在php中从数组中获取.org域?

如何在php中从数组中获取.org域?,php,regex,preg-match,Php,Regex,Preg Match,我有一个包含html标签、文本等的数组。我只想从列表中获取.org域 我的代码不起作用: <?php $list = htmlentities(file_get_contents('list.html')); preg_match("/^[a-zA-Z0-9-.]+(.org)$/", $list, $matches); var_dump ($matches); ?> 如果字符类中出现连字符(在方括号之间),则连字符必须是该类中的最后一个字符。因此,尝试交换句点和连字符的位

我有一个包含html标签、文本等的数组。我只想从列表中获取.org域

我的代码不起作用:

<?php

$list = htmlentities(file_get_contents('list.html'));

preg_match("/^[a-zA-Z0-9-.]+(.org)$/", $list, $matches);

var_dump ($matches);
?>


如果字符类中出现连字符(在方括号之间),则连字符必须是该类中的最后一个字符。因此,尝试交换句点和连字符的位置。除此之外,请举例说明您正在使用的内容,因为它不太清楚。如果您希望preg_match将
^
$
视为一行的开头和结尾,而不是整个字符串,则应设置
m
修饰符:
preg_match(/^[a-zA-Z0-9-.]+(.org)$/m”
。有帮助吗?内容:我想把.org域放在一个数组中。懒汉:结果是
array(0){}
你不能发布
list.html
的内容或者至少是其中的一部分吗?
$list = "google.com
    http://d.org
    google.org
    <ul>
        <li>www.yahoo.co.uk</li>
        <li>http://www.bsdflj.org.uk</li>
        <li>nsdfljsdf.org</li>
    </ul>";

preg_match_all("~([a-zA-Z0-9-.]+.org)[^\.]~s", $list, $matches);
var_dump ($matches[1]);
array(3) {
  [0]=>
  string(5) "d.org"
  [1]=>
  string(10) "google.org"
  [2]=>
  string(13) "nsdfljsdf.org"
}