Jump to content

Stuck on preg_match_all() help needed


prest

Recommended Posts

Hello there,

 

I'd like to get the Video ID from a Youtube RSS but I'm getting :

 

Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash

 

Tried several patterns but I really newbie on RegEx and don't know how it works exactly, tried to get a nice tutorial without luck so I'd like you to check it out please since I need it.

 

Source Code where you can find Video ID bold:

 

<link rel="alternate" type="text/html" href="http://www.youtube.com/watch?v=7Buoi_ElUKQ" />

 

 

My source:

 

 

$rss = file_get_contents($url);

// URL supports that function, already tested echoing $rss

 

preg_match_all("watch?v=([^*]+)/i", $rss , $videos, PREG_SET_ORDER);

// Need to get an array of matches so parameter is ok I think

 

 

Any idea?

 

Thank you so much for your help!

 

I'd appreciate a RegEx nice tutorial link too to avoid bothering you with this next time.

 

Link to comment
Share on other sites

First of all, thank you for your quick reply.

 

I'm only getting 7 matches while there are around 30, when echoing $videos array only get:

 

Array

Array

Array

Array

Array

Array

Array

 

Already tried this one :

 

preg_match_all("/videos\/([^\"]+)/i", $rss , $videos, PREG_SET_ORDER);

 

for this code:

 

<id>http://gdata.youtube.com/feeds/api/videos/7Buoi_ElUKQ</id> 

 

That would works too, but got same matches as before with same array content.

 

What is wrong on this code?

 

Thank you again.

Link to comment
Share on other sites

After double-checking function's documentation got to retrieve storaged data in the array, but get this :

 

qc6XUr4kG3A'/>machinimahttp://gdata.youtube.com/feeds/api/users/machinimaEntertainmentRUNESCAPE 

qc6XUr4kG3A'/>Runescape Gods Exposed - Episode 1 (machinima)http://gdata.youtube.com/feeds/api/videos/7Buoi_ElUKQ2009-06-20T00:14:51.000Z2009-09-08T11:20:40.000ZRUNESCAPE Runescape Gods Exposed - Episode 2 By TehNoobShow FOR MORE MACHINIMA GOTO: www.youtube.com Music Provided by www.freeplaymusic.commachinimahttp://gdata.youtube.com/feeds/api/users/machinimaEntertainmentRUNESCAPE Runescape Gods Exposed - Episode 2 By TehNoobShow FOR MORE MACHINIMA GOTO: www.youtube.com Music Provided by www.freeplaymusic.comRunescape, Gods, Exposed, machinima, tehnoobshow, mmorpg, video, game, episode3, massive, multiplayer, online, role, playing, pc, free, no, charge, interactive, on-line, gameplay, yt:quality=highRunescape Gods Exposed - Episode 2 (machinima)http://gdata.youtube.com/feeds/api/videos/Z5YZTHfr1P42009-07-16T00:14:43.000Z2009-09-07T22:46:20.000ZHALF LIFE Follow the thoughts of Dr. Gordon Freeman, a 27 year old physicist and neurotic individual. In this episode, Freeman meets the 

Z5YZTHfr1P4'/>machinimahttp://gdata.youtube.com/feeds/api/users/machinimaEntertainmentHALF LIFE Follow the thoughts of Dr. Gordon Freeman, a 27 year old physicist and neurotic individual. In this episode, Freeman meets the 

Z5YZTHfr1P4'/>Freeman's Mind: Episode 12 (half life machinima)http://gdata.youtube.com/feeds/api/videos/IurCl7plz802009-06-26T00:12:32.000Z2009-09-08T11:46:28.000ZRUNESCAPE Runescape 

 

First ID is the one I want but rest of text is useless to me right now, so how can I get only that code from :

 

<link rel="alternate" type="text/html" href="

/>

 

 

Can we make it stop when it reads " />   ?

 

Thank you again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.