对我有用,当值是双引号时,让我们发布一个示例,因为它在评论中并不清楚。
我创建了一个文件html.html
:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="some content">
</head>
<body>
<div>TODO write content</div>
</body>
</html>
然后是一个php:
<?php
$file = "html.html";
$dom = new DOMDocument();
$dom->loadHTMLFile($file);
$xpath = new DOMXPath($dom);
$name = 'description';
$query = '/html/head/meta[@name="'.$name.'"]/@content';
$contents = $xpath->query($query);
echo $contents->item(0)->value;
?>
输出是some content
您需要在第一个双引号之后关闭单引号,因此它们将保留在带引号的字符串中,然后放置变量,开始引用并再次放置双引号
编辑:
我使用了您发布的网站中的 HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css" media="screen">
<!--
#qm0 {position:relative;}
#qm0 a {display:block; white-space:nowrap; }
#qm0 div a {float:none;}
#qm0 div {visibility:hidden;position:absolute;}
#qm0 a {float: left; }
-->
</style>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Product1 Name</title>
<link href="n-defaultStyle.css" rel="stylesheet" type="text/css">
<meta http-equiv="pragma" content="no-cache">
<meta name="keywords" content=" Ilmfpnv, VrbfZgj, Fsikeprr Mluw">
<meta name="description" content="Beu Urb Hcsmihnurb cl c avlqclb ZtatcZq nrbc in unidrdpt cft mbvfp kj rmi isspulu. Uqwoiab in sf upq lkspuj jZ oed diirovs">
</head>
仍然没有问题,输出:
Beu Urb Hcsmihnurb cl c avlqclb ZtatcZq nrbc in unidrdpt cft mbvfp kj rmi isspulu. Uqwoiab in sf upq lkspuj jZ oed diirovs