Regex help

I’m stuck at regex again, basically, I need to get the following from this page using PHP:

In the source of http://www.youtube.com/watch?v=XLI9kiwe7LE

18%7Chttp%3A%2F%2Fv18.lscache5.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%252Coc%253AU0dWRVFUU19FSkNNNl9JTldD%26algorithm%3Dthrottle-factor%26itag%3D18%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1270195200%26key%3Dyt1%26signature%3DA2B51B48C8B73BE37B38C31E7A3B2E35BCEF1F2D.46FBC5EE46CEAAAA426666283BFF2BC035D6C58F%26factor%3D1.25%26id%3D5cb23d922c1eecb1%2C5%7Chttp%3A%2F%2Fv18.lscache4.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%252Coc%253AU0dWRVFUU19FSkNNNl9JTldD%26algorithm%3Dthrottle-factor%26itag%3D5%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1270195200%26key%3Dyt1%26signature%3D0D8B91625E99BBF456C1C1BBF46DA75FDDE01EE7.487DDCADA8B0909AE868363FE6199854FED1840A%26factor%3D1.25%26id%3D5cb23d922c1eecb1&csi_page_type=watch&keywords=freddie%2Cgibbs%2Crap%2Chip%2Chop%2Cgary%2Cindiana%2Cg.i.%2Cmidwest%2Cbig%2Cbizness&cr=AU&rv.1.url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DmgyBDFPP2TY&rv.6.thumbnailUrl=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FXqS7LiW_sLc%2Fdefault.jpg&rv.3.rating=5.0&fmt_list=18%2F512000%2F9%2F0%2F115%2C5%2F0%2F7%2F0%2F0&rv.7.id=x-H08eATPF0&rv.0.rating=5.0&rv.6.author=rapaddict22&rv.5.id=5tKo0gyllKs&rv.0.id=j_mryayr4Lk&sdetail=f%3Arelated%2Crv%3AvXCkaDciWHw&rv.5.url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5tKo0gyllKs&rv.3.title=Freddie+Gibbs+-+Im+A+Hustla&sourceid=yw&timestamp=1270170515&rv.0.author=rapaddict22&rv.3.thumbnailUrl=http%3A%2F%2Fi4.ytimg.com%2Fvi%2FOVsDs59Rvbg%2Fdefault.jpg&rv.2.author=rapaddict22&rv.6.url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXqS7LiW_sLc&fmt_map=18%2F512000%2F9%2F0%2F115%2C5%2F0%2F7%2F0%2F0&hl=en_US&rv.0.thumbnailUrl=http%3A%2F%2Fi3.ytimg.com%2Fvi%2Fj_mryayr4Lk%2Fdefault.jpg&rv.5.length_seconds=185&rv.7.author=OPAZOakaELMALDITO&rv.5.view_count=5214&rv.1.length_seconds=57&rv.3.id=OVsDs59Rvbg&rv.2.id=ec7jJCVB7gw&rv.2.length_seconds=180&t=vjVQa1PpcFM0n-vUpFfR5emeu0_nVLsGpAvFKM9B74c%3D&rv.6.id=XqS7LiW_sLc&rv.6.view_count=1466&rv.3.author=rapaddict22&rv.4.id=RgepEOp3Z1s&rv.1.view_count=101&rv.4.author=rapaddict22&rv.7.thumbnailUrl=http%3A%2F%2Fi1.ytimg.com%2Fvi%2Fx-H08eATPF0%2Fdefault.jpg&allow_embed=1&vq=auto&rv.2.rating=4.66666666667&rv.7.title=Lil+Eazy-E+feat.+Bone+Thugs+-+This+Ain%27t+A+Game&rv.1.id=mgyBDFPP2TY&rv.6.title=Freddie+Gibbs+-+Stay+High+remix&rv.4.length_seconds=73&rv.1.thumbnailUrl=http%3A%2F%2Fi2.ytimg.com%2Fvi%2FmgyBDFPP2TY%2Fdefault.jpg&rv.6.length_seconds=73&length_seconds=95&feature=related&enablejsapi=1&plid=AASDNp5b94tyYpKJ&fmt_stream_map=18%7Chttp%3A%2F%2Fv18.lscache5.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%252Coc%253AU0dWRVFUU19FSkNNNl9JTldD%26algorithm%3Dthrottle-factor%26itag%3D18%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1270195200%26key%3Dyt1%26signature%3DA2B51B48C8B73BE37B38C31E7A3B2E35BCEF1F2D.46FBC5EE46CEAAAA426666283BFF2BC035D6C58F%26factor%3D1.25%26id%3D5cb23d922c1eecb1%2C5%7Chttp%3A%2F%2Fv18.lscache4.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%252Coc%253AU0dWRVFUU19FSkNNNl9JTldD%26algorithm%3Dthrottle-factor%26itag%3D5%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1270195200%26key%3Dyt1%26signature%3D0D8B91625E99BBF456C1C1BBF46DA75FDDE01EE7.487DDCADA8B0909AE868363FE6199854FED1840A%26factor%3D1.25%26id%3D5cb23d922c1eecb1

If you decode this, and split them up, the output is:


http://v18.lscache5.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dWRVFUU19FSkNNNl9JTldD&algorithm=throttle-factor&itag=18&ipbits=0&burst=40&sver=3&expire=1270195200&key=yt1&signature=A2B51B48C8B73BE37B38C31E7A3B2E35BCEF1F2D.46FBC5EE46CEAAAA426666283BFF2BC035D6C58F&factor=1.25&id=5cb23d922c1eecb1,5


http://v18.lscache4.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dWRVFUU19FSkNNNl9JTldD&algorithm=throttle-factor&itag=5&ipbits=0&burst=40&sver=3&expire=1270195200&key=yt1&signature=0D8B91625E99BBF456C1C1BBF46DA75FDDE01EE7.487DDCADA8B0909AE868363FE6199854FED1840A&factor=1.25&id=5cb23d922c1eecb1&csi_page_type=watch&keywords=freddie,gibbs,rap,hip,hop,gary,indiana,g.i.,midwest,big,bizness&cr=AU&rv.1.url=http://www.youtube.com/watch?v=mgyBDFPP2TY&rv.6.thumbnailUrl=http://i1.ytimg.com/vi/XqS7LiW_sLc/default.jpg&rv.3.rating=5.0&fmt_list=18/512000/9/0/115,5/0/7/0/0&rv.7.id=x-H08eATPF0&rv.0.rating=5.0&rv.6.author=rapaddict22&rv.5.id=5tKo0gyllKs&rv.0.id=j_mryayr4Lk&sdetail=f:related,rv:vXCkaDciWHw&rv.5.url=http://www.youtube.com/watch?v=5tKo0gyllKs&rv.3.title=Freddie Gibbs - Im A Hustla&sourceid=yw&timestamp=1270170515&rv.0.author=rapaddict22&rv.3.thumbnailUrl=http://i4.ytimg.com/vi/OVsDs59Rvbg/default.jpg&rv.2.author=rapaddict22&rv.6.url=http://www.youtube.com/watch?v=XqS7LiW_sLc&fmt_map=18/512000/9/0/115,5/0/7/0/0&hl=en_US&rv.0.thumbnailUrl=http://i3.ytimg.com/vi/j_mryayr4Lk/default.jpg&rv.5.length_seconds=185&rv.7.author=OPAZOakaELMALDITO&rv.5.view_count=5214&rv.1.length_seconds=57&rv.3.id=OVsDs59Rvbg&rv.2.id=ec7jJCVB7gw&rv.2.length_seconds=180&t=vjVQa1PpcFM0n-vUpFfR5emeu0_nVLsGpAvFKM9B74c=&rv.6.id=XqS7LiW_sLc&rv.6.view_count=1466&rv.3.author=rapaddict22&rv.4.id=RgepEOp3Z1s&rv.1.view_count=101&rv.4.author=rapaddict22&rv.7.thumbnailUrl=http://i1.ytimg.com/vi/x-H08eATPF0/default.jpg&allow_embed=1&vq=auto&rv.2.rating=4.66666666667&rv.7.title=Lil Eazy-E feat. Bone Thugs - This Ain't A Game&rv.1.id=mgyBDFPP2TY&rv.6.title=Freddie Gibbs - Stay High remix&rv.4.length_seconds=73&rv.1.thumbnailUrl=http://i2.ytimg.com/vi/mgyBDFPP2TY/default.jpg&rv.6.length_seconds=73&length_seconds=95&feature=related&enablejsapi=1&plid=AASDNp5b94tyYpKJ&fmt_stream_map=18


http://v18.lscache5.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dWRVFUU19FSkNNNl9JTldD&algorithm=throttle-factor&itag=18&ipbits=0&burst=40&sver=3&expire=1270195200&key=yt1&signature=A2B51B48C8B73BE37B38C31E7A3B2E35BCEF1F2D.46FBC5EE46CEAAAA426666283BFF2BC035D6C58F&factor=1.25&id=5cb23d922c1eecb1,5

All I want from this is:


http://v18.lscache5.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dWRVFUU19FSkNNNl9JTldD&algorithm=throttle-factor&itag=18&ipbits=0&burst=40&sver=3&expire=1270195200&key=yt1&signature=A2B51B48C8B73BE37B38C31E7A3B2E35BCEF1F2D.46FBC5EE46CEAAAA426666283BFF2BC035D6C58F&factor=1.25&id=5cb23d922c1eecb1,5


http://v18.lscache4.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dWRVFUU19FSkNNNl9JTldD&algorithm=throttle-factor&itag=5&ipbits=0&burst=40&sver=3&expire=1270195200&key=yt1&signature=0D8B91625E99BBF456C1C1BBF46DA75FDDE01EE7.487DDCADA8B0909AE868363FE6199854FED1840A&factor=1.25&id=5cb23d922c1eecb1


http://v18.lscache5.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dWRVFUU19FSkNNNl9JTldD&algorithm=throttle-factor&itag=18&ipbits=0&burst=40&sver=3&expire=1270195200&key=yt1&signature=A2B51B48C8B73BE37B38C31E7A3B2E35BCEF1F2D.46FBC5EE46CEAAAA426666283BFF2BC035D6C58F&factor=1.25&id=5cb23d922c1eecb1,5

My script is currently working for some things, but not for others.

Can you help me get those 3 things in the above code from the source?

Thanks.

I’m not sure why you need the same thing 3 times?

Some pages have 2 or 3 different links, hence me getting 3 results to parse a different one randomly.

If you can get me 1 result successfully it’ll be fine.

Here’s how I recreated the first one.
If $text = the first string you gave, then…


$data = explode('%7C',$text);
$search = array('%3A','%2F','%3F','%3D','%26','%25');
$replace = array(':','/','?','=','&','%');
$string = str_replace($search,$replace,$data[1]);
$string = explode('=',$string);
$string[(count($string)-1)] = str_replace('%2C',",",$string[(count($string)-1)]);
$string = implode('=',$string);

$string is now set to the first line you gave as your result.

I can get that with split and urldecode… I want to get the code from YouTubes source ready to parse, thats all I need help with.

I’m not sure what you’re asking for. Your original post asks for a way to go from A to B… now it sounds like you’re asking how to get A out of the HTML source?

If so, it depends on what setup your server is using… cURL can get the data… fopen/fread…file_get_contents… and then you just manipulate it as you would a string. (or throw it through a parser and handle it that way).

I said I need to get the following from the page, meaning I need to get the first quote out of the YouTube source.

Any further help is appreciated.

Regards.