Jump to content

Get data from URL


Larry101

Recommended Posts

I see the link was on your own server, but if it wasn't....

 

If the url contains multiple unknown queries or not a link on your server, you can do this.

 

Grabs just the query, and also finds how many queries, and separates the queries and values.

 

<?php
$url = "http://www.youtube.com/watch?v=3fumBcKC6RE&feature=topvideos_music";
$url = trim($url);
//add http:// if is not present
if (substr($url, 0, 5) != "http:") {
$url = "http://$url";
}
$query_parse = parse_url($url, PHP_URL_QUERY);
$query_chunk = ltrim($query_parse, "?");
$query_array = explode("&", $query_chunk);
$query_number = 0;
foreach($query_array as $value_chunk){
$query_number = $query_number +1;
$query_value_array = explode("=", $value_chunk);
$query_value[] = $query_number."|".$query_value_array[0]."|".$query_value_array[1];
}

//the complete query
echo $query_chunk."<br />";

//queries array
foreach($query_value as $query_results){
$results = explode("|", $query_results);
$number = $results[0];
$query = $results[1];
$value = $results[2];

echo "<b>$number: Query: </b>".$query."<b>Value: </b>".$value."<br />";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/236426-get-data-from-url/#findComment-1215525
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.