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

Hello! Here is my sample text.... I need to use preg_match for multiple patterns... I need to find:

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


I used:

preg_match_all("/[(.*?), (.*?), '(.*?)', '(.*?)', '', '0', 0, 23, 0, '', '0', '(.*?)', '']/mis", $a, $hashtweet);
4
  • 2
    it looks like valid json, so php.net/manual/en/function.json-decode.php Commented Jun 24, 2013 at 13:13
  • you can also explode, but it is json. Commented Jun 24, 2013 at 13:14
  • valid json would be double-quotes " not single-quotes ' . i dont know if json_decode can handle that, if not str_replace helps Commented Jun 24, 2013 at 13:15
  • 1
    print_r(json_decode(str_replace("'", '"', $string))); Commented Jun 24, 2013 at 13:18

2 Answers 2

1

Here you go:

$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)
Sign up to request clarification or add additional context in comments.

Comments

1

Maybe strip the [] brackets and do explode(',', $input) (docs)?

Another idea: this looks like a valid JSON data, so json_decode (docs) should do the trick.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.