[英]getting value between alt of img tag
如何使用正則表達式獲取圖像的alt標簽之間的值,例如,我有<img class="sprite-ratings" alt="3 of 5 stars" src="http://c1.tacdn.com/img2/x.gif">
現在我希望在服務器端獲得5星中的3星。 誰能幫我?
此regex
將匹配: '/<img.*?alt="(.*?)".*>/'
preg_match('/<img.*?alt="(.*?)".*>/',$str,$match);
echo $match[1];
輸出:
3 of 5 stars
說明:
<img # Match the literal string
.*? # Match anything after (non-greedy)
alt=" # Upto the literal string
(.*?) # Capture everything after
" # Upto the literal
.*> # Match everything else up to the closing >
$res = preg_match("/<img[^>]+alt=\"([^>]*)\"[^>]*>/iU", $yourstring, $matches);
if ($res) {
echo "the alternative text is: " . $matches[1];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.