0
[-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);
4

2 回答 2

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)
于 2013-06-24T13:17:59.263 回答
1

也许去掉[]括号并做explode(',', $input)文档)?

另一个想法:这看起来像是一个有效的 JSON 数据,所以json_decodedocs)应该可以解决问题。

于 2013-06-24T13:18:14.873 回答