可以使用正则表达式来匹配HTML源码中input元素的id属性为guid且value属性不为空的情况。以下是一个示例的PHP代码:

$html = '<input type="text" id="guid123" value="12345" />
          <input type="text" id="guid456" value="" />
          <input type="text" id="guid789" />';

$pattern = '/<input.*?id="(guid\w+)".*?value="([^"]*)"/';

preg_match_all($pattern, $html, $matches, PREG_SET_ORDER);

foreach ($matches as $match) {
    $id = $match[1];
    $value = $match[2];
    
    if (!empty($value)) {
        echo "Input with id $id has non-empty value: $value\n";
    }
}

输出结果为:

Input with id guid123 has non-empty value: 12345

这个例子中,使用正则表达式/<input.*?id="(guid\w+)".*?value="([^"]*)"/来匹配HTML源码中的input元素。其中id="(guid\w+)"表示匹配id属性值为以guid开头的字符串,value="([^"]*)"表示匹配value属性的值。然后使用preg_match_all函数来找到所有匹配的结果,并通过循环遍历输出结果

php正则匹配html源码中input的id是guid的value

原文地址: http://www.cveoy.top/t/topic/iX9Y 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录