Home >Backend Development >PHP Tutorial >晕了 ,求个正则表达式 php的, 在线等

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

WBOY
WBOYOriginal
2016-06-23 14:10:54922browse

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>

想些个正则表达式,得到结果大约是这样的.死活写不出.功夫不到家..
求大神,取得单选框匹配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        )

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


回复讨论(解决方案)

在线等...

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

上面得出的结果是:

[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        )


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

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

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

$s=<<.+?]+name="(.+?)"[^>]+>([^<]+)  
Array
(
    [0] => Array
        (
            [0] => name="BTN_GROUP_59679208328481" value="22334875:SHIP_TO_HOME:3" onclick="" checked="">

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


首先谢谢版主,
这个好像还要对数据做二次处理吧.
就是循环数组判断哪个选择了.


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


首先谢谢版主,
这个好像还要对数据做二次处理吧.
就是循环数组判断哪个选择了.
不用判断,直接可以知道的
你把数组重组成你想要的数组就可以了



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


首先谢谢版主,
这个好像还要对数据做二次处理吧.
就是循环数组判断哪个选择了.
不用判断,直接可以知道的
你把数组重组成你想要的数组就可以了
倒是取出来了..呵呵.谢谢.

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

$s=<<.+?]+name="(.+?)"[^>]+>([^<]+)  
Array
(
    [0] => Array
        (
            [0] => name="BTN_GROUP_59679208328481" value="22334875:SHIP_TO_HOME:3" onclick="" checked="">

Statement:
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