[淘宝商城]
活动标题
……
……
我希望通过正则 将上面的内容 变成一串数组
array(
[0] =>array(
shopname => 淘宝商城,
activename=> 活动标题,
actimage => http://image.com/pic.gif,
acturl => http:/www.tmall.com/ //这个是活动标题的链接
),
[1] =>array(……)
……
);
就像上面一样输出数组
------解决方案--------------------
只用正则达到你的要求似乎不太可能。要处理一下。我贴下匹配结果。处理自己补充:
php code $str=
[淘宝商城]
活动标题
…… ……html;preg_match_all('#]*>(.*)#isu',$str,$arr);foreach($arr[1] as $v){ preg_match_all('#]*>(.*)#isu',$v,$ar[]);}print_r($ar);
------解决方案--------------------
php code$str =
[淘宝商城1]
活动标题
[淘宝商城2]
活动标题
html;/** *shopname => 淘宝商城, activename=> 活动标题, actimage => http://image.com/pic.gif, acturl => http:/www.tmall.com/ //这个是活动标题的链接 */$pattern = '~img.*(?';print_r($res);echo '';/**剩下的你懂的array( [0] => array ( [0] => http://image.com/pic.gif1 [1] => 淘宝商城1 [2] => http://www.tmall.com/1 [3] => 活动标题1 ) [1] => array ( [0] => http://image.com/pic.gif2 [1] => 淘宝商城2 [2] => http://www.tmall.com/2 [3] => 活动标题2 ))*/
