2014-01-06 49 views
0

匹配我有一个字符串:PHP的正则表达式 - 与空间

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 > *\'); 

我怎么能得到的*onchange ="...any..."* and *location attrib = location = \'index.php?route=checkout/cart&remove=46\' :*

用PHP正则表达式 价值?

+0

你有什么已经尝试过? – BenM

+0

你的字符串是不是'onchange'?或者是你的字符串的内容? –

+0

由于这个字符串,在它的最基本的层面上,它的HTML内容:[你不能用正则表达式解析非常规语言](http://stackoverflow.com/questions/1732454) – rockerest

回答

0

你的问题有点不清楚,但也许这就是你要找的。

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

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

print_r($matches); 

输出:

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