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
3
votes
4 answers

How to get only center domain name from url

I have many thousands of urls from which i only want to get name of domain for example http://google.com '; print_r($host['host']); echo ''; **//Output…
Sufyan
  • 506
  • 2
  • 6
  • 18
3
votes
2 answers

How can execute php scripts in bash?

I need parse uri in shell scripts. So, I tried to use php in bash as below. #!/bin/sh uri="http://www.google.com?key=value key="host" value=$(php -r "$parse = parse_url('$uri'); echo $parse['$key']") It has showing the following error. PHP Parse…
2
votes
4 answers

PHP - How to get $_GET Parameter without value

I need to know how to get the $_GET parameter from requested url. If I use for example $url = $_SERVER['REQUEST_URI']; $parse_url = parse_url($url, PHP_URL_QUERY); echo $parse_url; will output query=1, but I need only the parameter not parameter…
2
votes
1 answer

Running parse_url() on a string that may not contain the protocol

I'm trying to get the domain name and TLD (no subdomain) from a user-input URL string which may or may not have protocol, directories, subdomains, filenames, etc. In other words, given any of the…
brentonstrine
  • 21,694
  • 25
  • 74
  • 120
2
votes
1 answer

How to differentiate domains from longer URLs in PHP?

I receive URLs from a PHP form with the _POST method. I am sure they are URLs because jquery validate plugin tests them before sending. Then I process them in PHP. However, I want to make sure that : domain.com or domain.com/ end with a /. But, I…
yoann44
  • 43
  • 1
  • 7
1
vote
4 answers

Parsing webpage from php

I'm working on getting my new website up and I cannot figure out the best way to do some parsing. What I'm doing is trying to parse this webpage for the comments (last 3) the "whats new" page, permissions page, and the right-bar (the one with the…
Samuel
  • 4,337
  • 3
  • 29
  • 35
1
vote
3 answers
1
vote
2 answers

How To Extract Query Parts Of Url Onto Different Arrays By Separating Keys & Values?

I got this url: http://example.com/cat/subcat?var1=value1&var2=value2 I need to grab the query part's keys and values onto separate arrays. So the $query_string array should contain these values: var1=value1&var2=value2 Then, I want the $keys array…
I Ali
  • 41
  • 4
1
vote
1 answer

Nginx 1.17 + PHP + Open Server: parse_url with non-English (Russian) characters (letters) leads to wrong characters conversion

[UPD]: I've just double-checked. It behaves this way under Nginx 1.17 only. Apache works fine! The code: $url = '/Регистрация/?lala=123'; $res = parse_url($url); echo '
';
print_r($res);
echo '
'; Under Apache everything works fine. Under…
1
vote
1 answer

How to avoid php parse_url return false when parse "/s?a=12&b=12.3.3.4:1233" which has ":" in the params?

How to avoid php parse_url return false when parse ''/s?a=12&b=12.3.3.4:1233" which has ":" in the params?
zyfyy
  • 323
  • 3
  • 10
1
vote
1 answer

PHP: Parse_url w/ preg_replace to remove portion of referrer URL string

I'm trying to extract portions of a URL in PHP using parse_url and remove a portion of the [path] if it exists. For example, if my URL is "http://localhost/website/section/type/name/" and I want to remove the /website/ portion from the url…
nickpish
  • 839
  • 4
  • 24
  • 43
1
vote
1 answer

php: img src minus two folders

i have an url but i need "2015/02/3023.jpg" this is not working: $value is the url print_r(parse_url($value)); $tokens = explode('/', $value); echo…
1
vote
1 answer

PHP: Stripping protocol from Instagram API image urls

This is a snippet from an Instagram JSON: "images":{ "standard_resolution": { "url":"http:\/\/scontent-a.cdninstagram.com\/hphotos-xfa1\/t51.2885-15\/10593467_370803786404217_1595289732_n.jpg","width":640,"height":640} } I'd like to…
MultiformeIngegno
  • 6,959
  • 15
  • 60
  • 119
1
vote
1 answer

Make the URL path count backwards

I learned how to parse an URL and return me a specific part of it. For now, I'm currently working in a localhost server, which contains a long basename: localhost/mydocs/project/wordpress/mexico/cancun If I want to get the word mexico I would have…
Caio Ferrari
  • 319
  • 1
  • 3
  • 13
1
vote
1 answer

Parse_url not working correctly on staging server

I am facing a problem with parse_url function. if i use parse_url on my local system i am getting following output. Url for parsing used is www.youtube.com/embed/u-j1nx_HY5o Array ( [host] => www.youtube.com [path] => /embed/u-j1nx_HY5o )…
Amit Kumar
  • 3,384
  • 6
  • 25
  • 42