Grab video URL from external URL [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to access the URL of the video element from an external URL.
That's an example of the url I'm trying to access:
https://www.musical.ly/v/MzA4NTExODI2MDI0MjMzNDgxOTEyMzI.html
file_get_contents and curl return an html code without the video in it, what am I doing wrong?
Any PHP/jQuery solution would be great!

It seems like the MzA4NTExODI2MDI0MjMzNDgxOTEyMzI-part of the url is the video key.
They are calling: https://www.musical.ly/rest/v2/musicals/shareInfo?key=MzA4NT‌​ExODI2MDI0MjMzNDgxOT‌​EyMzI to fetch the video information in json format.
You could do the same and just use the videoUri from the json response?
Example
Just for fun, I created an example how to fetch it from the initial URL. This would of course need a bit of validation and such, but it is a working example:
<?php
$url = 'https://www.musical.ly/v/MzA4NTExODI2MDI0MjMzNDgxOTEyMzI.html';
// Extract the url path and explode the segments
$segments = explode('/', parse_url($url, PHP_URL_PATH));
if (isset($segments[2])) {
// We have the key segment so let's build the URL to fetch the info
$infoUrl = 'https://www.musical.ly/rest/v2/musicals/shareInfo?key=' . rtrim($segments[2], '.html');
$info = file_get_contents($infoUrl);
$info = $info ? json_decode($info, true) : null;
}
if (isset($info['result'], $info['result']['videoUri'])) {
// We have all we need, let's get the video uri
echo $info['result']['videoUri'];
} else {
die('No video URI found');
}

Related

Getting the part of the current URL in Laravel 7/8 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How to get the current URL without the first part dynamically?
For example:
www.google.com/en/second => /second
www.google.com/en/second/third => /second/third
Where to put the function or how to implement this in the current blade view?
You can use Request::segments:
implode('/', array_slice(request()->segments(), 1));
All http link:
$link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // www.google.com/en/second/third
Just requested link:
$requested_link = "$_SERVER[REQUEST_URI]"; // en/second/third
If you do not want any part of link, replace it with "":
str_replace("en/", "", $requested_link); // second/third
You can put this code anywhere in view or controller. For example in view:
<?php
function get_url(){
$requested_link = "$_SERVER[REQUEST_URI]";
return str_replace("en/", "", $requested_link);
}
?>
Get the current URL including the query string...
echo url()->full();

Recursion with array's PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a function (listarUrls ()) that returns / scans all the urls it finds on a web page.
I need that for each of the urls that the function returns to me, I return to the list / scan all the urls of that page
many times as requested by the user, that is
.If the user asks for 1 iteration of the url www.a.com, bring back:
-$arry[0] www.1.com
-$arry[1] www.2.com
-..... So with all the urls you find in www.a.com
.If the user asks for 2 iteration of the url www.a.com, bring back:
-$arry[0] www.1.com
-$arry[0][0] www.1-1.com
-$arry[0][1] www.1-2.com
-...So with all the urls you find in www.1.com
-$arry[1] www.2.com
-$arry[1][0] www.2-1.com
-$arry[1][1] www.2-2.com
-...So with all the urls you find in www.2.com
-...
.If the user asks for 3 iteration of the url www.a.com, bring back:
-$arry[0] www.1.com
-$arry[0][0] www.1-1.com
-$arry[0][0][0] www.1-1-1.com
-$arry[0][0][1] www.1-1-2.com
-...So with all the urls you find in www.1-1.com
-$arry[0][1] www.1-2.com
-$arry[0][1][0] www.1-2-1.com
-$arry[0][1][1] www.1-2-2.com
-...So with all the urls you find in www.1-2.com
-$arry[1] www.2.com
-$arry[1][0] www.2-1.com
-$arry[1][0][0] www.2-1-1.com
-$arry[1][0][1] www.2-1-2.com
-...So with all the urls you find in www.2-1.com
-$arry[1][1] www.2-2.com
-$arry[1][1][0] www.2-2-1.com
-$arry[1][1][1] www.2-2-2.com
-...So with all the urls you find in www.2-2.com
-...
Could someone shed some light on the subject please?
This is web scraping with the option to instruct how much deep to investigate.
We can have a function definition like below:
function scrapeURLs($url,$steps,&$visited_urls = []);
Here, $url is the current URL we are scraping. $steps is which step we are investigating. If $steps == 1 at any point in our recursive function, we stop scraping further. $visited_urls is to make sure we aren't visiting same URL twice for scraping.
Snippet:
<?php
ini_set('max_execution_time','500');
libxml_use_internal_errors(true); // not recommended but fine for debugging. Make sure HTML of the URL follows DOMDocument requirements
function scrapeURLs($url,$steps,&$visited_urls = []){
$result = [];
if(preg_match('/^http(s)?:\/\/.+/',$url) === 0){ // if not a proper URL, we stop here, but will have to double check if it's a relative URL and do some modifications to current script
return $result;
}
$dom = new DOMDocument();
$dom->loadHTMLFile($url);
// get all script tags
foreach($dom->getElementsByTagName('script') as $script_tag){
$script_url = $script_tag->getAttribute('src');
if(!isset($visited_urls[$script_url])){
$visited_urls[$script_url] = true;
$result[$script_url] = $steps === 1 ? [] : scrapeURLs($script_url,$steps - 1,$visited_urls); // stop or recurse further
}
}
// get all anchor tags
foreach($dom->getElementsByTagName('a') as $anchor_tag){
$anchor_url = $anchor_tag->getAttribute('href');
if(!isset($visited_urls[$anchor_url])){
$visited_urls[$anchor_url] = true;
$result[$anchor_url] = $steps === 1 ? [] : scrapeURLs($anchor_url,$steps - 1,$visited_urls);
// stop or recurse further
}
}
/* Likewise, you can capture several other URLs like CSS stylesheets, image URLs etc*/
return $result;
}
print_r(scrapeURLs('http://yoursite.com/',2));
array_walk_recursive — Apply a user function recursively to every member of an array
https://www.php.net/manual/en/function.array-walk-recursive.php

Compare two URL-s with or without www in PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have Iframe that inserts data into my DB from another websites using $_SERVER['HTTP_HOST'] value.
One of the column inserted is website URL that can start with
www (e.g: www.viber.ge) or without it (just viber.ge).
I need to compare URL that Iframe has already inserted into DB to URL that Iframe is on at the moment.
But there can be www as subdomain name
So how can I be sure starting www is subdomain or not?
(I putted hello at the top but it is not showing up -_- )
Question is not about comparing "www.viber.ge" with "viber.ge"
it is more about comparing "www.www.viber.ge"(which I think can be inserted into the DB as "www.viber.ge")
with www.viber.ge (which I think can be inserted into DB as "viber.ge" or "www.viber.ge").
Additional question:
is it possible user to go to "www.www.viber.ge" and $_SERVER to save it as "www.viber.ge" (subdomain)?
You can use str_replace and remove the shorter url from the longer.
If what is left is "www." Only then it's the same domain.
$url1 = "www.viber.ge";
$url2 = "viber.ge";
If(strlen($url1) > strlen($url2)){
If(str_replace($url2,"",$url1) == "www."){
Echo "same domain";
}Else{
Echo "not same";
}
}Else{
If(str_replace($url1,"",$url2) == "www."){
Echo "same domain";
}Else{
Echo "not same";
}
}
https://3v4l.org/XtHWr

Check whether website is using sitemap and robots files [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How do I know whether the website is using robot.txt and sitemap.txt? I have done extracting keyword, description, title; however I am unable to find the way to code to check whther the website is using robot.txt and sitemap.txt.
I am doing something like this http://www.seoptimer.com/report/loadster.in/5553240531d12
Use file_get_contents:
$robotsContents = file_get_contents("http://targetdomain.com/robots.txt");
$sitemapContents = file_get_contents("http://targetdomain.com/sitemap.xml");
Check if contents are false, false will mean 404 Not Found, then check if it's not HTML contents (because some sites redirect every URL) with strpos($robotsContents, '<html') === false, if there is no tag, that mean it can be txt ou xml file.
So:
function pathExistsAndIsNotHtml($path) {
$contents = #file_get_contents($path);
return ! empty($contents) && strpos($contents, '<html') === false;
}
if(pathExistsAndIsNotHtml("http://targetdomain.com/robots.txt")) {
echo 'http://targetdomain.com/robots.txt';
} else {
echo 'There is no robots.txt';
}
if(pathExistsAndIsNotHtml("http://targetdomain.com/sitemap.xml")) {
echo 'http://targetdomain.com/sitemap.xml';
} else {
echo 'There is no sitemap.xml';
}

PHP hand variable to another php document [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to get a variable which I declared in one php file to another without including the whole first php
while($row = mysql_fetch_assoc($sql)) {
// Urlaubstage ausgeben
if($row['frtutage'] < 1) {
$verbraucht = "0";
} else {
$verbraucht = $row['frtutage'];
}
$resturlaub = $row['miturlaubstage'] + $row['mitutagevorjahr'] - $verbraucht;
$urlaubgesamt = $row['miturlaubstage'] + $row['mitutagevorjahr'];
I need the variable $resturlaub in the second PHP without calculating the variable again.
How do I do this? Or is it even possible?
Thanks.
edit: the first php file is about calculating vacation days and how much I have remaind after taking a few vacation days, in the second file I need the calculation of the remaining days then, so I just want to use the variable again and not calculate it again
You can try somehting like
$var = 'random_query';
$page= 'yourpage.com/?my_var='.serialize($var);
header("Location: $page");
exit;
and in your page you can get the value by
if (isset($_GET['my_var']))
{
$my_var = unserialize($_GET['my_var']);
}
But it would depend on the size of that variable that you need to pass, and what is the purpose of the scripts.
If you don't want to include the whole first php file but only a variable then you should create a third file (called: variables.php or config.php for example).
Then include variables.php in both file so the variable will be shared among your scripts

Categories