Php 获取img标记的alt之间的值
如何使用正则表达式获取图像的alt标记之间的值 e、 g我有 现在我想要五颗星中的三颗星 我想把它放在服务器端。 有人能帮我吗?这个正则表达式将匹配:'/'Php 获取img标记的alt之间的值,php,regex,Php,Regex,如何使用正则表达式获取图像的alt标记之间的值 e、 g我有 现在我想要五颗星中的三颗星 我想把它放在服务器端。 有人能帮我吗?这个正则表达式将匹配:'/' $res = preg_match("/<img[^>]+alt=\"([^>]*)\"[^>]*>/iU", $yourstring, $matches); if ($res) { echo "the alternative text is: " . $matches[1]; } 说明: <i
$res = preg_match("/<img[^>]+alt=\"([^>]*)\"[^>]*>/iU", $yourstring, $matches);
if ($res) {
echo "the alternative text is: " . $matches[1];
}
说明:
<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 >
此正则表达式将匹配:'/'
说明:
<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 >
我想你可以得到这样的。$value。我需要通过regelar表达式。当图像不存在或盲人试图在你的网站上冲浪时,alt标记用于替代文本。最好使用数据标签。例如,data stars=3/5。我想你可以得到这样的值。$value。我需要通过regelar表达式。当图像不存在或盲人试图在你的网站上冲浪时,alt标记用于替代文本。最好使用数据标签。例如,数据星=5中的3。是的,它正在工作。谢谢你,凯伊。这对我真的是一个很大的帮助。是的,它现在正在工作。谢谢你,凯伊。这对我真的是一个很大的帮助。是的,它现在正在工作。谢谢@sudo_O。这对我来说真的是一个很大的帮助。+1,尽管使用[^]*匹配双引号的附件是更好的形式:是的,它现在正在工作。谢谢@sudo_O。这对我来说真的是一个很大的帮助。+1,尽管使用[^]*来匹配双引号的附件是更好的形式:
<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 >