0
我有一個數據屬性中的網址,我需要得到的第一個:如何獲取數據屬性值?
<div class="carousel-cell">
<img onerror="this.parentNode.removeChild(this)"; class="carousel-cell-image" data-flickity-lazyload="http://esportareinsvizzera.com/site/wp-content/uploads/8.jpg">
</div>
<div class="carousel-cell">
<img onerror="this.parentNode.removeChild(this);" class="carousel-cell-image" data-flickity-lazyload="http://www.finanziamentiprestitimutui.com/wp-content/uploads/2014/09/esportazioni-finanziamento-credito.jpg">
</div>
<div class="carousel-cell">
<img onerror="this.parentNode.removeChild(this);" class="carousel-cell-image" data-flickity-lazyload="http://www.infologis.biz/wp-content/uploads/2013/09/Export.jpg">
</div>
<div class="carousel-cell">
<img onerror="this.parentNode.removeChild(this);" class="carousel-cell-image" data-flickity-lazyload="http://www.cigarettespedia.com/images/2/25/Esportazione_horizontal_name_ks_20_s_green_italy.jpg">
</div>
我一直在閱讀大量像this one和this one的答案,但我不是一個PHP的人。
我用它來獲取第一張圖片,但現在我需要實際的數據屬性值,而不是
<?php
$custom_image = usp_get_meta(false, 'usp-custom-4');
$custom_image = htmlspecialchars_decode($custom_image);
$custom_image = nl2br($custom_image);
$custom_image = preg_replace('/<br \/>/iU', '', $custom_image);
preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i',$custom_image, $image);
?>
<img src="<?php echo $image['src']; ?>" alt="<?php the_title(); ?>">
嘿非常感謝,我應該這樣做嗎? $ mySrc = $ items [0] - > getAttribute('data-flickity-lazyload');
提供有關您的錯誤的更多信息:您是否看到任何警告消息? '$ mySrc'的內容是什麼?將'$ custom_image'加載到'DOMDocument'時,它的內容是什麼? – gmc
如果我確實echo $ custom_image我得到'