我需要帮助才能使用#4bbedd
函数从style="background-color:#4bbedd;vertical-align:middle;"
获取值PHP
如果有xPath
,那么谢谢我需要
这是
HTML
代码
HTML代码
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="pickerContainer" data-reactid=".0.1.1.1.3.0.0.1.1.1.1">
<div class="ColorPicker" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0">
<a class="ui small interactive circular label" style="background-color:#4bbedd;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Aquatic Blue">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Aquatic Blue.0">Aquatic Blue</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Aquatic Blue.1"></i>
</a>
<a class="ui small interactive circular label" style="background-color:#CCCCCC;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Ash">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Ash.0">Ash</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Ash.1"></i>
</a>
<a class="ui small interactive circular label" style="background-color:#999999;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Athletic Heather">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Athletic Heather.0">Athletic Heather</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Athletic Heather.1"></i>
</a>
<a class="ui small interactive circular label" style="background-color:#F27EB2;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Azalea">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Azalea.0">Azalea</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Azalea.1"></i>
</a>
<a class="ui small interactive circular label" style="background-color:#000000;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Black">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Black.0">Black</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Black.1"></i>
</a>
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
<?php
$object = new DOMDocument();
$object->loadHTML('<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="pickerContainer" data-reactid=".0.1.1.1.3.0.0.1.1.1.1">
<div class="ColorPicker" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0">
<a class="ui small interactive circular label" style="background-color:#4bbedd;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Aquatic Blue">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Aquatic Blue.0">Aquatic Blue</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Aquatic Blue.1"></i>
</a>
<a class="ui small interactive circular label" style="background-color:#CCCCCC;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Ash">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Ash.0">Ash</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Ash.1"></i>
</a>
<a class="ui small interactive circular label" style="background-color:#999999;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Athletic Heather">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Athletic Heather.0">Athletic Heather</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Athletic Heather.1"></i>
</a>
<a class="ui small interactive circular label" style="background-color:#F27EB2;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Azalea">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Azalea.0">Azalea</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Azalea.1"></i>
</a>
<a class="ui small interactive circular label" style="background-color:#000000;vertical-align:middle;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Black">
<span class="toolTip" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Black.0">Black</span>
<i class="checkmark icon" style="display:none;" data-reactid=".0.1.1.1.3.0.0.1.1.1.1.0.$Black.1"></i>
</a>
</div>
</div>
</body>
</html>');
$xPathObject= new DOMXPath($object);
$result=$xPathObject->query("/html/body/div/div/a[1]");
$desiredResult="";
foreach($result as $data)
{
foreach($data->attributes as $attribute)
{
if($attribute->name=="style")
{
$desiredResult= explode(";",explode(":", $attribute->value)[1])[0];
}
}
}
echo $desiredResult;