Harinder
Harinder

Reputation: 1257

preg_match() to get data from youtube api

I have Some text from youtube api

<content type='text'> 
Song: Haske
Music: Atul Sharma
Lyrics: Pargat Singh
Singer: Harjeet Harman
Music On : T-Series

For latest Punjabi Music Subscribe 
http://www.youtube.com/tseriesapnapunjab
http://www.facebook.com/tseriesapnapunjab

</content>

i want to get these fields out with preg_match() field require are song:, music:, lyrics:, singer: how can i get this out (i dont full detail just need required fields)... i am new to preg_match() please help

Edit

i was trying this but dont no how to get it working with my need

$string = "/brown fox jumped [0-9]/";

$paragraph = "The brown fox jumped 1 time over the fence. The green fox did not. Then the brown fox jumped 2 times over the fence";

if (preg_match_all($string, $paragraph, &$matches)) {
 foreach($matches[0] as $a){
echo $a;
}

Upvotes: 0

Views: 180

Answers (1)

fullybaked
fullybaked

Reputation: 4127

This is an excellent tool for trying out regular expressions and slowly building up your solution

http://www.phpliveregex.com/

You want to look at the preg_match_all method to find multiple matches in the same string

This will work for the example posted, by I encourage you to figure out how it works

preg_match_all('/^(\w+):\s(.*?)$/m', $input, $output, PREG_SET_ORDER);

You will need PREG_SET_ORDER to group the matches together by set

Upvotes: 3

Related Questions