Questions tagged [parse-url]

url-parsing is the process of splitting a Universal Resource Locator into its component parts usually to extract parameters made as part of a request or to filter requests. The url http://parts.web.site/discount?part=51762 might be parsed to identify "/discount" and "part=51762" was requested

Overview

A Universal Resource Locator is a character string that represents an internet resource.

An example of a URL might be:

ftp://my.photo.site:21/static/photo?id=82713&format=png

url-parsing is the process of splitting a URL into its component parts, usually to retrieve request parameters or to filter requests. The example above might be parsed into:

scheme: ftp
domain: my.photo.site
port: 21
path: /static/photo
query_string: id=82713 format=png

The process of parsing a url can be managed by a library like the python urlparse, by server frameworks or string processing functions like regex.

Links

94 questions
77
votes
13 answers

Parse an URL in JavaScript

How do I parse an URL with JavaScript (also with jQuery)? For instance I have this in my string, url = "http://example.com/form_image_edit.php?img_id=33" I want to get the value of img_id I know I can do this easily with PHP with parse_url(), but I…
Run
  • 54,938
  • 169
  • 450
  • 748
45
votes
6 answers

php parse_url reverse -- parsed url

Is there a way to reverse the url from a parsed url? $url = 'http://www.domain.com/dir/index.php?query=blabla#more_bla'; $parse = parse_url($url); print_r($parse); /* array( 'scheme'=>'http://', etc.... ) */ $revere = reverse_url($parse); //…
Val
  • 17,336
  • 23
  • 95
  • 144
20
votes
3 answers

PHP: Remove 'WWW' from URL inside a String

Currently I am using parse_url, however the host item of the array also includes the 'WWW' part which I do not want. How would I go about removing this? $parse = parse_url($url); print_r($parse); $url = $parse['host'] . $parse['path']; echo $url;
ritch
  • 1,760
  • 14
  • 37
  • 65
18
votes
3 answers

How do I decode a URL and get the query string as a HashMap?

I have a URL like this: http%3A%2F%2Fexample.com%3Fa%3D1%26b%3D2%26c%3D3 I parsed it with hyper::Url::parse and fetch the query string: let parsed_url = hyper::Url::parse(&u).unwrap(); let query_string = parsed_url.query(); But it gives me the…
Saeed M.
  • 2,216
  • 4
  • 23
  • 47
9
votes
14 answers

getting youtube video id the PHP

I am currently writing a webapp in which some pages are heavily reliant on being able to pull the correct youtube video in - and play it. The youtube URLS are supplied by the users and for this reason will generally come in with variants one of…
Udders
  • 6,914
  • 24
  • 102
  • 194
9
votes
6 answers

parse_url() PHP works strange

I'm trying to get host from url using parse_url. But in some queries i get empty results. Here is my function: function clean_url($urls){ $good_url=array(); for ($i=0;$i
Djos
  • 89
  • 1
  • 2
7
votes
1 answer

why is parse_url returning fragment?

I have the following URL: http://sub.mysite.com/store/?store=Fine+Ting&storeid=3726&test1=value1&test2=value2 Using print_r(parse_url($url)) gives me this: Array ( [scheme] => http [host] => sub.mysite.com [path] => /store/ [query] =>…
Steven
  • 19,224
  • 47
  • 152
  • 257
4
votes
2 answers

Check whether remote URL has a valid image extension

How can I check that a remote URL has a valid image extension? What I want to do is upload images via link using PHP copy('http://website.com/image.jpg', '/upload/filename.jpeg'); Code works fine but i want to check whether entered url has a valid…
Jordyn
  • 1,133
  • 2
  • 13
  • 28
4
votes
4 answers

parse_url() returns an error when example.com is passed

According to following code if $host_name is something like example.com PHP returns a notice: Message: Undefined index: host but on full URLs like http://example.com PHP returns example.com. I tried if statements with FALSE and NULL but didn't…
Zim3r
  • 580
  • 2
  • 14
  • 36
4
votes
2 answers

PHP Parse URL - Domain returned as path when protocol prefix not present

I am trying to parse URL's in PHP where the input could be any of the following: Code: $info = parse_url('http://www.domainname.com/'); print_r($info); $info = parse_url('www.domain.com'); print_r($info); $info =…
Matt
  • 537
  • 1
  • 5
  • 14
3
votes
1 answer

Duplicating content with PHP_URL_QUERY with RSS feeds

Background: I've created a dynamic website where lots of the content is generated by RSS feeds from themoneyconvert.com The website displays live currency rates like such: Hopefully you get the idea of the contents I'm displaying across a 3 column…
keenProgrammer
  • 438
  • 2
  • 10
3
votes
0 answers

Is there a function in urllib or the stdlib that recognizes a SSH-like URL vs. a local path?

rsync recognizes if a destination is local rsync a/ /local/path/ or if it is remote rsync a/ user@example.com:/path/to/. Is there a similar URL parsing tool, built-in in Python's stdlib? The key thing with rsync or scp is that we don't want to…
Basj
  • 41,386
  • 99
  • 383
  • 673
3
votes
2 answers

parse_url() problem when one of parameters is url

I call a php script http://site.com/process.php that takes a url as one of its parameters. for= http://site.com/process.php?for=http://www.anotherwebsite.com I then do this and try to parse_url() but parse_url() gives a parse error. $uri =…
zmol
  • 2,834
  • 5
  • 26
  • 29
3
votes
1 answer

Is there something like parse_url in Objective C?

Is there there somethings like parse_url() equivalent in Objective C? I like the simplicity of this function in PHP and need the same thing in an iPhone app. For example: given a url http://www.google.com/?someting=somthing I can get a nice data…
Jason
  • 31
  • 4
3
votes
1 answer

Scala: How to parse a URL with custom protocols

I need to parse URLs that might contain protocols different than http or https... and since if try to create a java.net.URL object with a URL like nio://localhost:61616 the constructor crashes, I've implemented something like this: def…
j3d
  • 9,492
  • 22
  • 88
  • 172
1
2 3 4 5 6 7