PHP fetch with file_get_contents() funtion - php

i want to get m3u8 link from this site on other php page
for example : this is the site : "view-source:http://lideo.ru/embed/9528"
i want to extract only this m3u8 to other php page : http://hls.lideo.ru/liveapp/09528_bd608448e6c4a218d16b1f7b4018f6e8/index.m3u8?tokenhash=TIai4tLuWZHdLOS5mjNOqw
I'm tried this code but seems not working
$url = "http://lideo.ru/embed/9528";
$contents = file_get_contents($url);
preg_match('#m3u8([^"]+)#',$contents,$rtmp);
$link = urldecode($link[0]);
echo $link;
Any help please because i'm not soo good in php :)
thanks

Try this:
$url = "http://lideo.ru/embed/9528";
$contents = file_get_contents($url);
preg_match('/(https?\:\/\/[^\']*\.m3u8\?[^\']*)/', $contents, $result);
$link = urldecode($result[0]);
echo $link;

Related

PHP file_get_contents not showing url link

I'm having an issue with php file_get_content(), I have a txt file with links where I created a foreach loop that display multiple links in the same webpage but it's not working, please take a look at the code:
<?php
$urls = file("links.txt");
foreach($urls as $url) {
file_get_contents($url);
echo $url;
}
The content of links.txt is: https://www.google.com
Result: Only a String displaying "https://www.google.com"
Another code that works is :
$url1 = file_get_contents('https://google.com');
echo $url1;
This code returns google's homepage, but I need to use first method with loops to provide multiple links.
Any idea?
Here's one way of combining the things you already had implemented:
$urls = file("links.txt");
foreach($urls as $url) {
$contents = file_get_contents($url);
echo $contents;
}
Both file and file_get_contents are functions that return some value; what you had to do is putting return value of the latter one inside a variable, then outputting that variable with echo.
In fact, you didn't even need to use variable: this...
$urls = file("links.txt");
foreach($urls as $url) {
echo file_get_contents($url);
}
... should have been sufficient too.

get specific variable from html5player external source

I'm trying to get the html5player.setVideoUrlHigh var from an external source that renders like this:
<script>
logged_user = false;
var static_id_cdn = 2;
var html5player = new HTML5Player('html5video', '38295'); //this is the video ID
if (html5player) {
html5player.setVideoTitle('video title goes here');
html5player.setVideoUrlHigh('https://random-prefix-here.site-url.com/videos/mp4/random-part-of-url');
...
}
</script>
Firstly, I do file_get_contents to get the embed code:
$videoID = 38295;
$url = file_get_contents('https://www.site-url.com/embedframe{$videoID}');
then, I look for a url match that contains specific parts like (site-url.com/videos/mp4/) to eco it, like this:
preg_match('/https:\/\/[^\"]*/\.site-url\.com\/videos\/mp4\/[^\"]*/', $url, $matches, PREG_OFFSET_CAPTURE);
$videoURL = ($matches[0][0]);
echo '=>' . $videoURL;
but this is not working... Where am I failing?
Please keep in mind that both random-prefix-here and random-part-of-url should be replaced by regex in a possible solution.
UPDATED
I already tried this also, witouth any results:
$url = 'http://www.site-url.com/embedframe38295/';
$content= file_get_contents($url);
preg_match_all('#html5player.setVideoUrlHigh\((.+?)\')', $url, $matches, PREG_OFFSET_CAPTURE);
$videoURL = ($matches[0][0]);
echo $videoURL;

PHP preg_match not working perfectly

In my code I am trying to extract url only from my string using preg_match() function but its not working properly I tried all possible references but nothing works for me.
Here is the string example
FileID = "http://downloader.example.com/myfile/Josh.mp4";
My Expectation
http://downloader.example.com/myfile/Josh.mp4
Here is my php code
<?php
$stringURL = "FileID = \"http://downloader.example.com/myfile/Josh.mp4\";";
preg_match('/FileID(.*)=(.*)"(.*)"/U', $stringURL,$matches);
if (isset($matches[0])) {
$myurl = $matches[0];
} else {
$myurl = "http://";
}
echo $myurl;
?>
Why not it like this?
preg_match('/https?\:\/\/[^\" ]+/i', $stringURL,$matches);

Replace the page from a url using php

I have this type of urls stored in a php variable:
$url1 = 'https://localhost/mywebsite/help&action=something';
$url2 = 'https://localhost/mywebsite/jobs&action=one#profil';
$url3 = 'https://localhost/mywebsite/info&action=two&action2=something2';
$url4 = 'https://localhost/mywebsite/contact&action=one&action2=two#profil';
I want to replace the page help, jobs, info, contact with home in a very simple way, something like this:
echo replaceUrl($url1);
https://localhost/mywebsite/home&action=something
echo replaceUrl($url2);
https://localhost/mywebsite/home&action=one#profil
echo replaceUrl($url3);
https://localhost/mywebsite/home&action=two&action2=something2
echo replaceUrl($url4);
https://localhost/mywebsite/home&action=one&action2=two#profil
So here is the solution i found:
function replaceUrl($page){
$pieces = explode("/", $page);
$base = '';
for ($i=0; $i<count($pieces)-1; $i++) $base .= $pieces[$i].'/';
$hash = strpbrk($pieces[count($pieces)-1], '&#');
return $base.'home'.$hash;
}
You'll want to add something like
RedirectMatch 301 help(.*) home$1
to your .htaccess file. I'm not sure PHP is the correct tool for the job.
If you actually want to modify a string with the value of that (which is what your tags and.. comments indicate), you'll want to do:
$url = "https://localhost/mywebsite/help&action=something#profil"
$url = str_replace("help", "home", $url);
echo $url; // https://localhost/mywebsite/home&action=something#profil

Getting A Certain Part Of A Url

How can i get a certain part of a URL i have searched google and read a few tutorials but can't seem to get my head around it maybe someone can show me from the example below.
Here is my code
<?php
include "simple_html_dom.php";
$title = "fast";
$html = file_get_html("http://www.imdb.com/find?q=".urlencode($title)."&s=all");
$element = $html->find('[class="result_text"] a', 1);
$link = $element->href;
echo $link;
// Clear dom object
$html->clear();
unset($html);
?>
Now this echos
/title/tt0109772/?ref_=fn_al_tt_2
But i only want the imdb id.
tt0109772
So can someone explain or show me how to do this please
thanks
If it's always the subdir:
echo basename(dirname($link));
you can Use explode():
$str = "/title/tt0109772/?ref_=fn_al_tt_2";
$arrUrl = explode("/",$str);
$id = $arrUrl[2];
echo $id;
demo
You can use explode like:
$parts = explode("/", $url);
This will split URL to array. Then check what index you want.. and get it like:
$id = $parts[3];
You can debug with: print_r($parts);
Not the most elegant way, but
$link = '/title/tt0109772/?ref_=fn_al_tt_2';
$imdb_id = explode('/', $link);
$imdb_id = $imdb_id[2];
echo $imdb_id;
Will work.
Try this code: (source)
$path = parse_url($url, PHP_URL_PATH);
$segments = explode('/', $path);
Then I think you need $segments[1] to get the IMDB id.

Categories