晕了 ,求个正则表达式 php的, 在线等

WBOY
Release: 2016-06-23 14:10:54
Original
870 people have browsed it

html是这样的

<div class="itemCartContaine"><input type="radio" name="BTN_GROUP_59679208328481" value="22334875:SHIP_TO_HOME:1" onclick=""><input type="radio" name="BTN_GROUP_59679208328481" value="22334875:SHIP_TO_HOME:2" onclick=""><input type="radio" name="BTN_GROUP_59679208328481" value="22334875:SHIP_TO_HOME:3" onclick="" checked=""><textarea id="IncludeMessage" name="TEXTAREA_59679208328481" onclick="WALMART.checkout.shipping.giftMsgOnClick(this);" onkeyup="WALMART.checkout.shipping.giftMsgLimiter(this, 59679208328481)">Enter your gift message here</textarea></div><div class="itemCartContaine"><input type="radio" name="BTN_GROUP_59679208328482" value="22334876:SHIP_TO_HOME:1" onclick=""><input type="radio" name="BTN_GROUP_59679208328482" value="22334876:SHIP_TO_HOME:2" onclick="" checked=""><input type="radio" name="BTN_GROUP_59679208328482" value="22334876:SHIP_TO_HOME:3" onclick=""><textarea id="IncludeMessage2" name="TEXTAREA_59679208328482" onclick="" onkeyup="">Enter your gift message here2</textarea></div>
Copy after login

想些个正则表达式,得到结果大约是这样的.死活写不出.功夫不到家..
求大神,取得单选框匹配checked的值和下面textarea的值,最后想要的的大约是这样的
[1] => Array        (            [0] => BTN_GROUP_59679208328481            [1] => BTN_GROUP_59679208328482            [2] => TEXTAREA_59679208328481            [3] => TEXTAREA_59679208328482        )    [2] => Array        (            [0] => 22334875:SHIP_TO_HOME:3            [1] => 22334876:SHIP_TO_HOME:2            [2] => Enter your gift message here            [3] => Enter your gift message here2        )
Copy after login

就用is,不用isu
可以实现吗


回复讨论(解决方案)

在线等...

$pattern='/<input type="radio" name="([^"]*?)" value="([^"]*?)" ([^>]*?)>(.*?)<input type="radio" name="([^"]*?)" value="([^"]*?)" ([^>]*?)>(.*?)<input type="radio" name="([^"]*?)" value="([^"]*?)" ([^>]*?)>(.*?)<textarea id="([^"]*?)" name="([^"]*?)" ([^>]*?)>([^<]*?)<\/textarea>/sm';
Copy after login
Copy after login
Copy after login
Copy after login

上面得出的结果是:

[1] => Array        (            [0] => BTN_GROUP_59679208328481            [1] => BTN_GROUP_59679208328482        )    [2] => Array        (            [0] => 22334875:SHIP_TO_HOME:1            [1] => 22334876:SHIP_TO_HOME:1        )    [3] => Array        (            [0] => onclick=""            [1] => onclick=""        )    [4] => Array        (            [0] =>             [1] =>         )    [5] => Array        (            [0] => BTN_GROUP_59679208328481            [1] => BTN_GROUP_59679208328482        )    [6] => Array        (            [0] => 22334875:SHIP_TO_HOME:2            [1] => 22334876:SHIP_TO_HOME:2        )    [7] => Array        (            [0] => onclick=""            [1] => onclick="" checked=""        )    [8] => Array        (            [0] =>             [1] =>         )    [9] => Array        (            [0] => BTN_GROUP_59679208328481            [1] => BTN_GROUP_59679208328482        )    [10] => Array        (            [0] => 22334875:SHIP_TO_HOME:3            [1] => 22334876:SHIP_TO_HOME:3        )    [11] => Array        (            [0] => onclick="" checked=""            [1] => onclick=""        )    [12] => Array        (            [0] =>             [1] =>         )    [13] => Array        (            [0] => IncludeMessage            [1] => IncludeMessage2        )    [14] => Array        (            [0] => TEXTAREA_59679208328481            [1] => TEXTAREA_59679208328482        )    [15] => Array        (            [0] => onclick="WALMART.checkout.shipping.giftMsgOnClick(this);" onkeyup="WALMART.checkout.shipping.giftMsgLimiter(this, 59679208328481)"            [1] => onclick="" onkeyup=""        )    [16] => Array        (            [0] => Enter your gift message here            [1] => Enter your gift message here2        )
Copy after login


然后再取下标2,5,8,16的就是结果了

应该是2,6,10,16才是匹配需要的内容

提供正则,然后你自己再处理下就可以实现。

$s=<<.+?]+name="(.+?)"[^>]+>([^<]+)
Copy after login
Copy after login

Array
(
[0] => Array
(
[0] => name="BTN_GROUP_59679208328481" value="22334875:SHIP_TO_HOME:3" onclick="" checked="">

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!