2013-05-03 35 views
0

我从YouTube API的preg_match()从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> 

我想这些领域不与的preg_match()字段需要的歌曲:,音乐:,歌词:,歌手写一些文字:我怎样才能得到这一点(我不全部细节刚需必填项)......我是新来的preg_match(),请帮助

编辑

我是想这一点,但不没有如何得到它的工作与我的需要

$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; 
} 
+0

更改'$ string =“/ brown fox jump [0-9] /”;'to'$ string =“/ brown fox jumped([0-9] )+ /“;' – reikyoushin 2013-05-03 14:14:11

回答

3

这是一个尝试的正则表达式,并慢慢建立你的解决方案

http://www.phpliveregex.com/

你想看看preg_match_all方法找到多个匹配的相同的字符串

这一个极好的工具将工作的例子张贴,我鼓励你弄清楚它是如何工作的

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

您将需要PREG_SET_ORDER通过设置将匹配组合在一起

+0

Thx ..... it works;) – Harinder 2013-05-03 14:21:47