Reputation: 165
<content type='application/x-shockwave-flash' src='https://www.youtube.com/v/f4LxBKN9ank?version=3&f=videos&app=youtube_gdata'/>
How could I get only the f4LxBKN9ank number? all my attepts to construct the preg_match failed. Thanks for tips.
EDIT
<yt:statistics favoriteCount='0' viewCount='106281'/>
<yt:rating numDislikes='9' numLikes='569'/>
How to retrive viewCount and the numDislikes/Likes
Upvotes: 2
Views: 576
Reputation: 3506
You can try with:
<?php
preg_match('#www\.youtube\.com\/v\/([\w\-]+)\?#', $string, $match);
$id = $match[1];
echo $id;
For your other question, I strongly discourage you to use a regex for parsing HTML/XML.
You should go for something like phpQuery or DOM.
Upvotes: 1
Reputation: 18392
Not that cool but regular expression are not that "fast". str_replace is much faster. BTW: "parse_url" rocks: http://www.php.net/manual/de/function.parse-url.php
<?php
$data = str_replace(array("path" => "/v/"),array(''),parse_url('https://www.youtube.com/v/f4LxBKN9ankversion=3&f=videos&app=youtbe_gdata'));
var_dump($data['path']);
// string 'f4LxBKN9ank' (length=11)
Upvotes: 2