Php 处理字符串以获取下载url

Php 处理字符串以获取下载url,php,Php,我想从中获取下载url 用于脱机安装程序x86和x64,作为字符串。我该怎么做 我可以用file_get_contents()获取页面 $page=file\u get\u contents('https://www.java.com/de/download/manual.jsp'); 我需要哪些函数来处理字符串 我需要这部分源代码: <a title="Download der Java-Software für Windows Offline" href="http://javadl.

我想从中获取下载url 用于脱机安装程序x86和x64,作为字符串。我该怎么做

我可以用
file_get_contents()获取页面

$page=file\u get\u contents('https://www.java.com/de/download/manual.jsp');

我需要哪些函数来处理字符串

我需要这部分源代码:

<a title="Download der Java-Software für Windows Offline" href="http://javadl.sun.com/webapps/download/AutoDL?BundleId=113217">
Windows Offline</a>



问题是url在版本发布后可能会发生更改。

Preg\u match会起作用

preg_match("'<a title=\"Download der Java-Software für Windows Offline\" href=\"(.*?)\">(.*?)</a>'si", $source, $match);
preg_match(“si”,$source,$match);
对于64位版本,情况类似

preg_match("'<a title=\"Download der Java-Software für Windows \(64-Bit\)\" href=\"(.*?)\">(.*?)</a>'si", $source, $match);
preg_match(“si”,$source,$match);
在这两种情况下,匹配[1]将提供下载链接。这些模式依赖于“title”属性中的文本,因此,如果该属性没有改变,并且下载链接也没有改变,则不会出现问题。

$page=file\u get\u contents('https://www.java.com/de/download/manual.jsp');
$page = file_get_contents('https://www.java.com/de/download/manual.jsp');

preg_match("'<a title=\"Download der Java-Software für Windows Offline\" href=\"(.*?)\">(.*?)</a>'si", $page, $match);
preg_match("'<a title=\"Download der Java-Software für Windows \(64-Bit\)\" href=\"(.*?)\">(.*?)</a>'si", $page, $match1);

$d_x86 = $match[0];
$d_x64 = $match1[0];

preg_match("'http*://\w+.\w+.\w+/\w+/\w+/\w+.\w+=\d+'", $d_x86, $match3);
preg_match("'http*://\w+.\w+.\w+/\w+/\w+/\w+.\w+=\d+'", $d_x64, $match4);

$d_x86_url = $match3[0];
$d_x64_url = $match4[0];

echo "<a href=\"$d_x86_url\">Download aktuellste JRE für Windows x86</a><br>";
echo "<a href=\"$d_x64_url\">Download aktuellste JRE für Windows x64</a>";
preg_match(“‘si’,$page,$match”); preg_match(“‘si’,$page,$match1”); $d_x86=$match[0]; $d_x64=$match1[0]; preg_match(“'http*://\w+。\w+。\w+/\w+/\w+/\w+。\w+=\d+'”,$d_x86,$match3); preg_match(“'http*://\w+。\w+。\w+/\w+/\w+/\w+。\w+=\d+'”,$d_x64,$match4); $d_x86_url=$match3[0]; $d_x64_url=$match4[0]; 回声“
”; 回声“;
我建议您使用Beauty访问HTML文档中所有必需的节点和属性:

<?php

$dom = new DOMDocument();
$dom->loadHTMLFile('https://www.java.com/de/download/manual.jsp');//load and parse document

$links = $dom->getElementsByTagName('a');//get all 'a' tags in document
foreach ($links as $link) {//iterate on all 'a' tags
    if($link->getAttribute('title') == 'Download der Java-Software für Windows Offline')
    {
        echo $link->nodeValue . '<br/>';//or do whatever you want
    }
}

?>

非常感谢,可能是重复的。这对我有用。非常有趣和有用的功能。
<?php

$dom = new DOMDocument();
$dom->loadHTMLFile('https://www.java.com/de/download/manual.jsp');//load and parse document

$links = $dom->getElementsByTagName('a');//get all 'a' tags in document
foreach ($links as $link) {//iterate on all 'a' tags
    if($link->getAttribute('title') == 'Download der Java-Software für Windows Offline')
    {
        echo $link->nodeValue . '<br/>';//or do whatever you want
    }
}

?>