簡體   English   中英

php preg_match_all多種模式

[英]php preg_match_all multiple patterns

[-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
超級低音
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);

干得好:

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

也許剝離[]括號並做explode(',', $input)docs )?

另一個想法:這看起來像一個有效的JSON數據,所以json_decodedocs )應該可以解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM