如何在PHP中的“单词”或“单词”之后获取字符串

时间:2017-04-02 05:24:25

标签: php html css xpath

我需要帮助才能使用#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>

1 个答案:

答案 0 :(得分:1)

PHP code demo

<?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;