将这些结果拆分为数组
我真的很难制作一些正则表达式来将:
Child Non Peak @ $10.75 USD <br/>
<input name="quan0" maxlength="1" size="1" class="star_N"/> <br>
Infant Non Peak @ $13.75 USD <br/>
<input name="quan1" maxlength="1" size="1" class="star_N"/> <br>
Adult Non Peak @ $13.75 USD <br/>
<input name="quan2" maxlength="1" size="1" class="star_N"/> <br>
Senior Non Peak @ $12.50 USD <br/>
<input name="quan3" maxlength="1" size="1" class="star_N"/> <br>
Member Adult Non Peak @ $12.75 USD <br/>
<input name="quan4" maxlength="1" size="1" class="star_N"/> <br>
Member Senior Non Peak @ $11.50 USD <br/>
<input name="quan5" maxlength="1" size="1" class="star_N"/> <br>
Member Child Non Peak @ $9.75 USD <br/>
<input name="quan6" maxlength="1" size="1" class="star_N"/> <br>
变成一个数组,就像
array (
value: Child Non Peak @ $10.75 USD
price: 10.75
有人可以帮忙吗?我已经有了这段非常复杂的正则表达式,但它不适合目的。
preg_match_all('/class="t12">(?P<type>\w+)[\s@]*(?P<cost>\$[\d.]*)\s+USD(.*)name="(?P<input>quan\w+)"/msU',
$output,
$matches,
PREG_SET_ORDER);
I'm really struggling to make some regex to turn:
Child Non Peak @ $10.75 USD <br/>
<input name="quan0" maxlength="1" size="1" class="star_N"/> <br>
Infant Non Peak @ $13.75 USD <br/>
<input name="quan1" maxlength="1" size="1" class="star_N"/> <br>
Adult Non Peak @ $13.75 USD <br/>
<input name="quan2" maxlength="1" size="1" class="star_N"/> <br>
Senior Non Peak @ $12.50 USD <br/>
<input name="quan3" maxlength="1" size="1" class="star_N"/> <br>
Member Adult Non Peak @ $12.75 USD <br/>
<input name="quan4" maxlength="1" size="1" class="star_N"/> <br>
Member Senior Non Peak @ $11.50 USD <br/>
<input name="quan5" maxlength="1" size="1" class="star_N"/> <br>
Member Child Non Peak @ $9.75 USD <br/>
<input name="quan6" maxlength="1" size="1" class="star_N"/> <br>
into an array thats like
array (
value: Child Non Peak @ $10.75 USD
price: 10.75
Could anyone assist? I have this largely complex piece of regex already but its not fit for purpose.
preg_match_all('/class="t12">(?P<type>\w+)[\s@]*(?P<cost>\$[\d.]*)\s+USD(.*)name="(?P<input>quan\w+)"/msU',
$output,
$matches,
PREG_SET_ORDER);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
给出了下一个结果:
gave the next result:
([a-zA-Z ]+ @ \$(\d+\.\d{2}) USD)
应该会给你很好的结果[a-zA-Z ]+< /code> 是产品名称,
@
位于产品和价格之间\$(\d+\.\d{2})
价格,group 捕获至少 1 位数字,后跟 .后跟 2 位数字
USD
捕获最后一个空格和货币参考([a-zA-Z ]+ @ \$(\d+\.\d{2}) USD)
should probably give you good results[a-zA-Z ]+
is the product name,@
is between product and the price\$(\d+\.\d{2})
price,group
captures atleast 1 digit followed by a . followed by 2 digitsUSD
captures the last space and currency reference使用像 DOMDocument 这样的 DOM 解析器来检查元素。
使用正则表达式解析 HTML 可能会导致意想不到的后果。
Use a DOM parser like DOMDocument to inspect the elements.
Using regex to parse HTML may lead to unintended consequences.