简体   繁体   English

PHP正则表达式-与空间匹配

[英]php regex - Matching with space

I have a string: 我有一个字符串:

 onchange = "(getURLVar(\'route\') == \'checkout/cart\' || getURLVar(\'route\') == \'checkout/checkout\') ? location = \'index.php?route=checkout/cart&remove=46\' : $(\'#cart\').load(\'index.php?route=module/cart&remove=46\' + \' #cart > *\');

how i can get value of *onchange ="...any..."* and *location attrib = location = \\'index.php?route=checkout/cart&remove=46\\' :* 我如何获取*onchange ="...any..."* and *location attrib = location = \\'index.php?route=checkout/cart&remove=46\\' :*

with php regex ? 与PHP正则表达式?

Your question is a bit unclear, but maybe this is what you're looking for. 您的问题尚不清楚,但是也许这就是您想要的。

$string = 'onchange=\'trueorfalse\'&location=\'index.php?route=checkout/cart&remove=46\'';

preg_match_all("/onchange='([^']+)'[.]*&location='([^']+)'/",$string, $matches);

print_r($matches);

Output: 输出:

Array
(
    [0] => Array
        (
            [0] => onchange='trueorfalse'&location='index.php?route=checkout/cart&remove=46'
        )

    [1] => Array
        (
            [0] => trueorfalse
        )

    [2] => Array
        (
            [0] => index.php?route=checkout/cart&remove=46
        )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM