[英]php get_tags() to list all the tags for the products in a specific category in woocommerce
[英]php - get all the values for a specific attribute for all input tags on a website
我的目标是从html.txt上提供的html源中的每个<input>
标记中获取“ name”属性的所有值。 我需要有关正则表达式以及if语句的帮助,因为现在它仅输出使用preg_match找到的第一个值,而不输出其余的值(它甚至不检查name属性是否在输入标记中)。 另外,我也在尝试修复正则表达式,因此它实际上并未显示name =部分。
<?php
$myfile = fopen('html.txt', 'r');
$subject = fread($myfile,filesize("html.txt"));
$pattern='/name="([^"]*)\"/';
if(preg_match($pattern, $subject, $hits)){
echo "values: $hits[0]";
}
?>
示例输出:
values: name="title"
与其使用正则表达式来查找属性和值,不如解析html dom。 使用simpleXML或http://php.net/manual/zh/domdocument.loadhtml.php基于文档的HTML DOM创建一个数组,然后遍历该数组以找到输入元素及其属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.