我将在下面回答您的问题,但您是否考虑过使用嵌入?查看此处了解更多信息:http://codex.wordpress.org/Embeds
最简单的正则表达式如下所示http\\:\\/\\/.*\\b
下面是一个实际的例子:
<?php
$file = \'test.txt\';
$fp = fopen($file, \'r\');
$contents = fread($fp, filesize($file));
$matches = array();
preg_match_all(\'/http\\:\\/\\/.*\\b/\', $contents, $matches);
print_r($matches);
?>
我引用的文件如下所示:
http://wordpress.stackexchange.com/questions/12809/retrieving-all-links-from-a-post
http://www.youtube.com/
http://ca3.php.net/manual/en/function.preg-match.php
返回结果如下所示:
Array
(
[0] => Array
(
[0] => http://wordpress.stackexchange.com/questions/12809/retrieving-all-links-from-a-post
[1] => http://www.youtube.com
[2] => http://ca3.php.net/manual/en/function.preg-match.php
)
)