Im building my own forum where you can use diffrent types of BBcode and one of them is [youtube][/youtube] to embed youtube videos,
The idea is to make it idiot-proof, the user can enter the full lenght url or just the code to the video like this
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg[/youtube]
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg&feature=related[/youtube]
[youtube]AJ3_kndmeCg[/youtube]
Here is my code that get the code out of a full lenght url,
<?php
$getpost=$_POST['post'];
$getpost=preg_replace("'\[youtube\].*?=(.*?)&.*?\[/youtube\]'is",'yt link is \\1',$getpost);
$getpost=preg_replace("'\[youtube\].*?=(.*?)\[/youtube\]'is",'yt link is \\1',$getpost);
$getpost=preg_replace("'\[youtube\](.*?)\[/youtube\]'is",'yt link is \\1',$getpost);
?>
The results are:
yt link is AJ3_kndmeCg
yt link is AJ3_kndmeCg
yt link is AJ3_kndmeCg
It works perfectly if I only want to embed 3 youtube videos,
But if i wanted to embed 6 youtube videos like this:
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg[/youtube]
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg&feature=related[/youtube] [youtube]AJ3_kndmeCg[/youtube]
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg[/youtube]
[youtube]http://www.youtube.com/watch?v=AJ3_kndmeCg&feature=related[/youtube]
[youtube]AJ3_kndmeCg[/youtube]
The results are:
yt link is AJ3_kndmeCg
yt link is AJ3_kndmeCg[/youtube]
yt link is AJ3_kndmeCg
yt link is http://www.youtube.com/watch?v=AJ3_kndmeCg
[youtube]AJ3_kndmeCg
Do you see that^^ the tags still remain on two lines and one of the lines show a full lenght URL,
I'd rather use an existing BBCode parsing library like http://www.christian-seiler.de/projekte/php/bbcode/index_en.html which also allows you to define your own bb tags, and turn them into the HTML you want.
;)
Wow, this was a real toughie of a regex to write.
Got it for you in one:
$getpost=preg_replace('#\[youtube\].*?(?:v=)?([^?&[]+)(&[^[]*)?\[/youtube\]#is',
'yt link is \\1', $getpost);
This will work for all the cases you supplied. It will not work if the link begins with a part other than 'v=' (for example, 'http://www.youtube.com/watch?foo=bar&v=AJ3_kndmeCg').
Enjoy!
Related
I'm creating a video site using PHP, and I want to insert video source code from a PHP URL.
For example, if I want to get Episode 1 from PHP, I want it like this:
example.com/player.php?=episode1
For Episode 2:
example.com/player.php?=episode2
I don't understand how to link all of the source pages with the main index page.
How can I accomplish this task?
Here's a way you could do it: Use a form on your homepage (index.html?) to select which video you want, and send it to player.php using a GET method. Then use the following on player.php:
<?php
$select = $_GET['select']; //This will be the number input for the video number
echo("<video><source src="episode$select.mp4"></video>"); //This will source the video named `episodeX.mp4`, where `X` is the select value from the form on `index.html`.
?>
Just ask if you need any additional clarification.
I need to fetch some images using google Reverse image search which is not supported by the API, but thankfully, you can query google with a direct link to the image and it still shows results, so:
$googleURL = "https://www.google.com/searchbyimage?&image_url=".$imageURL;
echo $googleURL;
Output:
https://www.google.com.au/search?tbs=sbi:AMhZZiu9rNRW4ETWGjN9XYQKsa21UHM7j_1TjMjXvYyNH1knVTyMGZGNmS2yme4CsQb0T7UViTyNrG4e8u_1xLY-dZCU16wkfdUakeY7idDwyMge78nT--Grpll4t9_1fp4YPTsJyKRUANzw1Iyctsko7OZbkYES3VUHtyNy9l9RJf12YOdEvVOxSZCO6-JPxO0PpZ5p79Rr-eDUrqENWYVbk4qojafKMTVfuXvoACQ9iykI-DMVbP9n_1o0YkdKTdUeK2r30wg4Oe2BqspoXlI_11rxySuK6TolPM6z58E6erTT0bnYfXTlyDMBfOwgSfhbn2ipLrNHgNdqyk-YhmMP0_1ZzqVyZrgMz-I5cfH9N65nX6bhZfos0lgr8_15V6ZHtX0_1p8s5r229JDrwzlwnjwOBLgP1inmEORCaKOlcfHbyPnU3n04pIfLGu5fWYpbmFJwtK_1vaJvS0uFb6Pkh_1uv0wvz_10yf4O6E1IvBSoMudcYy4cmJ1zegJJ9L50C0bzXFIRUb62lcPJWbkZNR44Tz378nOSXd-PND0JfKQ-TujT3KfC_1O241knvr9Eb3LbuvncGiCMoPgxlUY4r9B_1KWchNWhJVTJz9omeiygwz5K_13YkjuLg52UF6YWvLedCxgRoUpuj9kFdmYt-b9Tn2VEZG8yfiLm3OTkZnlVYtPF87LLQAHH24VpLMoV0oDllHDK3xOXhvusl_1K2Me9tTdK15PPG7oreeWfYRztQwTpG4iB5GAnaj687OQukvxX5hNFIqXx_1QSuNooDhIP1eJl-6QYfuI4MPasj6flSMom7HYTSjyjcsQKw0Prj1bBsJY6qH1qyLrF1f1_1Ql0COERnbOV7O5mTOuTkNWarmR5wzE06qbgsrtT95ENqafd81ppHbA0Jyg-xQ8TLV-dSp1QDAtiYAHI_11tCwsDtrak4jDS4qAfEJCw_1lb9urJqqajvp25jLH2_1mN3u0eeW7xNF-PljofyhI0iIWYSg6ghyOVRIaT_1c6klKUPvOrquZy8hMCZWHb3CYZNGJeKTnACCyYW1MNVUsYnoFWORN6hvkVlUk0beFXvA_1W2vaoedLjj-fN1y8_1dPOiBROLYtv85nq01csCKk7Eib6p2b_131wEeQBYocoYU0sGTv2_1dhOvSXRPGTnrbZlNDbJFUtH4pF9tMQj5-Fh_1lw9TTXGCjQ9UjOSLD5q7tNjCQU1As1uCQBvmZvxo7J3gZSAcj_19wXfHZCOsA8g-WA97V-2b62ia4RFOehQ38hoXoK7MCSDLnVtJTsKQz9HuEreXm8qGQlbDzfr7JFuHHe2MOyChwnL_1gzRnZd8uv2OIM0nzKh_1wg4T1KCXv3NSGNkSyNxpYXFJ161Sv3NpQQI3epBMiYA_1AcQDiCxOTQvWj00e5EXaXN22CDRWRq3uk4HWj2eXcR6-TGmsYEfSGX9nyQwK1DHp9yaNjk9Bal7rNHUAe_1eMDsCWW9htaLyiMTio0eXyTumVrlt7ShZVd8oSPOj8U0ilY9owH95jz7LsI8vUnzF-FC2m_1yNt3xe4ZAcsRTbYQXTN3Ga76vTQBPu8oz0gkYmDTA&gws_rd=cr&ei=wAHVVJOVLIeeugSZ64A4
.. now on this page, I need to follow the link to the actual results page, so my condition would look like:
if a.text == 'Large'
elseif a.text == 'Medium'
elseif a.text == 'Visually similar images'{
// crawl the link
// get direct links of top 10 results
}
But I'm not sure how to:
get the href if the condition a.text == 'Large' is met since Simple HTML DOM Parser or PHPQuery neither have this like jQuery.
On fetching the results page, how to trigger a mousedown even to get the full-size image URLS because this is what I see in the source: jsaction="mousedown:irc.rl;keydown:irc.rlk"
Here's quick screencast of what I'm looking to do: https://www.dropbox.com/s/c8g7fs5m5zqcegb/2015-02-07_08-56-23.mp4?dl=0 (5.9mb)
You can use Regular Expresssions to find the matching link.
If you check the HTML Code of the Google Image Search a bit more closely, you see there is actually also a href param in the Link (Example) which you can follow with just another crawl. There you can parse out the large image again with Regular Expressions.
Hey guys so I have a basic PHP application that loads a page with a video on it from one of those free TV streaming sites. You set the episode, season and show you wish to view and the server application parses the HTML tag of the iFrame that contains that video. The application works by parsing the HTML page with the PHP preg_match_all() method to get all occurrences of the iFrame HTML tag. I use the following string as the pattern, "/iframe .*\>/". This works for about half of the video players on the site, but for some reason comes up dry with all of the others.
For examples the video at http://www.free-tv-video-online.me/player/novamov.php?id=huv5cpp5k8cia which hosted on a video site called novamov is easily parsed. However, the video displayed at http://www.free-tv-video-online.me/player/gorillavid.php?id=8rerq4qpgsuw which is hosted on gorillavid, is not found by the preg_match_all() function despite it clearly being displayed in the HTML source when the element is inspected using chrome. Why is my script no returning the proper results and why is this behaviour dependant on the video player the video is using? Please could someone explain?
Try:
$dom = new DOMDocument; #$dom->loadHTML('yourURLHere');
$iframe = $dom->getElementsByTagName('iframe');
foreach($iframe as $ifr){
$ifrA[] = $ifr->getAttribute('src');
}
Now, the $ifrA Array should have your iframe src's.
I've built a blog similar to wordpress. On my home page, I take the entire blog post, throw it through a function, and only display an excerpt of it. I want to go through and shrink my videos to a specific width/height. The code in the post could look like:
[vimeo width="700" height="400"] // (the 700 & 400 could be any values).
I basically want to find that, then change it to:
[vimeo width="300" height="200"] // this will be preset/hard coded.
You can use regular expressions through preg_replace() to do the filtering. Just load your whole blog post into $BlogPost. The RegEx pattern may need to be altered to allow for variations in syntax and spacing (i.e. width = '700', etc.)
<?php
$FilteredBlogPost = preg_replace('/(.*vimeo width=")\d+(" height=")\d+(".*)/im', '${1}300${2}200${3}', $BlogPost);
?>
unless you want to scrape the video, put it on your server, resize it with some video dedicated libraries and then stream it from your server, the solution is client related (ie: HTML. not PHP)
Here is a nice tutorial on how to achieve that with youtube videos - i think exactly the same applies in your case too
Right now I have a variable: $blogbody which contains the entire contents of a blog.
I'm using the following to convert URLS to clickable links:
$blogbody = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","\\0", $blogbody);
And the following to resize embedded video:
$blogbody = preg_replace('/(width)=("[^"]*")/i', 'width="495"', $blogbody);
The problem I'm running into is the embedded video not working, comes back with an Access Forbidden error (403). If I remove the line to convert URLS to links, the embedded video works fine. Not sure how to get these two working together. If anyone else has a better solution to converting URLS to clickable links and resizing embedded video let me know!
This might be happening because the link which you use to embed the video also gets his <a href=''> tags added. So instead of just converting all links, check that they don't have ' or " directly behind or in front of them - this will make sure that the embedded videos' links won't get anchor tags.