php preg_match_all多种模式

时间:2013-06-24 13:12:38

标签: php find preg-match design-patterns preg-match-all

[-27439367, 160818667, 'http:\/\/cs13110.vk.me\/u109515688\/video\/l_97403fde.jpg', 'Super Bass', '', '0', 38674081, 37, 0, '2:34', '3', '_8cb245a336c2e35049', '']

您好!这是我的示例文本....我需要使用preg_match进行多种模式...我需要找到:

1. -27439367
2. 165375317
3. http://cs6067.vk.me/u189929178/video/l_02613a05.jpg
4.超级低音
5. 0
6. 38674081
7. 37
8. 2:34
9. 0
10. 3
11. _8cb245a336c2e35049


我用过:

preg_match_all("/[(.*?), (.*?), '(.*?)', '(.*?)', '', '0', 0, 23, 0, '', '0', '(.*?)', '']/mis", $a, $hashtweet);

2 个答案:

答案 0 :(得分:1)

你走了:

$json = "[-27439367, 160818667, 'http:\/\/cs13110.vk.me\/u109515688\/video\/l_97403fde.jpg', 'Super Bass', '', '0', 38674081, 37, 0, '2:34', '3', '_8cb245a336c2e35049', '']" ;
$json = preg_replace("/'/", '"', $json); //Replace single quotes by double quotes
$obj = json_decode($json);

var_dump($obj);

array (size=13)
  0 => int -27439367
  1 => int 160818667
  2 => string 'http://cs13110.vk.me/u109515688/video/l_97403fde.jpg' (length=52)
  3 => string 'Super Bass' (length=10)
  4 => string '' (length=0)
  5 => string '0' (length=1)
  6 => int 38674081
  7 => int 37
  8 => int 0
  9 => string '2:34' (length=4)
  10 => string '3' (length=1)
  11 => string '_8cb245a336c2e35049' (length=19)
  12 => string '' (length=0)

答案 1 :(得分:1)

可能会删除[]括号并执行explode(',', $input)docs)?

另一个想法:这看起来像一个有效的JSON数据,因此json_decodedocs)应该可以做到这一点。