這是一個例子,你可以在你的情況下使用:
$content = file_get_contents('bookmarks.html');
運行以下命令:
<?php
$content = '<html>
<title>Random Website I am Crawling</title>
<body>
Click <a href="http://clicklink.com">here</a> for foobar
Another site is http://foobar.com
</body>
</html>';
$regex = "((https?|ftp)\:\/\/)?"; // SCHEME
$regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)[email protected])?"; // User and Pass
$regex .= "([a-z0-9-.]*)\.([a-z]{2,4})"; // Host or IP
$regex .= "(\:[0-9]{2,5})?"; // Port
$regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?"; // Path
$regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?"; // GET Query
$regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; // Anchor
$matches = array(); //create array
$pattern = "/$regex/";
preg_match_all($pattern, $content, $matches);
print_r(array_values(array_unique($matches[0])));
echo "<br><br>";
echo implode("<br>", array_values(array_unique($matches[0])));
輸出:
Array
(
[0] => http://clicklink.com
[1] => http://foobar.com
)
http://clicklink.com
http://foobar.com
它可能會幫助大家,如果你能忍受的類型的書籤備份文件的例子,你想支持(每個瀏覽器) – scoates 2010-12-12 18:41:58
網景格式爲常見的是:http:/ /msdn.microsoft.com/en-us/library/aa753582(v=vs.85).aspx – Matthew 2010-12-12 18:56:34