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
0
votes
1 answer

Adding + before result

I want to add + in result so it appear as "+alrajhi12245" $url = http://mydomain.com/alrajhi12245/invoice; $parse = parse_url($url); $explode = explode('/', $parse['path']); $md = $explode[1]; How can i do?
Dr.Mezo
  • 807
  • 3
  • 10
  • 25
0
votes
5 answers

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
user3375691
  • 113
  • 1
  • 2
  • 8
0
votes
2 answers

Can this snippet be further optimized / organized?

From my related question here at SO I've come up with the following PHP snippet: $url = parse_url($url); if (is_array($url)) { $depth = 2; $length = 50; if (array_key_exists('host', $url)) { $result =…
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
0
votes
1 answer

javascript str-match cannot use

I need to parse url240 and url360 from a string. But i cant do it. On PHP it is very easy: preg_match('/&url240=(.*?)&/mis', $string, $C); But I cant do it on javascript. My javascript code: var str =…
0
votes
2 answers

PHP's "parse_url" in JavaScript

I wrote a JavaScript replica of PHP's parse_url function. As far as I have wrote by now, the fucnction does the job and returns a JS object... But is there a better way to do this: function parse_url( url ) { if(typeof url == 'string') { …
user1386320
0
votes
1 answer

Using Parse_Url to strip url and rebuild within a foreach loop

I want to strip the Host and Path elements from the "URL" in an array using a foreach loop. I am doing this as I am comparing results from different search engines and currently very few are "matching" due to slight difference with how search…
user2562455
  • 33
  • 1
  • 9
0
votes
1 answer

determining default port for scheme

Is there a php command to determine the default port for a given url? parse_url only seems to return the port if it is explicitly specified in the url, but my function needs to return the correct port…
Greg
  • 12,119
  • 5
  • 32
  • 34
0
votes
2 answers

How to store parse_url as a string in PHP?

I have the following code: $array = parse_url($_SERVER['HTTP_REFERER']); $Ur = $array['host']; which displays the domain just fine, but when I use this with sessions, it doesn't work. Also, I tested it with gettype and it returns Null? I thought…
Keith Donegan
  • 26,213
  • 34
  • 94
  • 129
0
votes
2 answers

Determine current domain character length

I am parsing domains and running into a problem handling subdomains. If the domain is http://www.google.co.uk, I want to obtain the length of google which is 6. I am using parse_url() to return the host in this case www.google.co.uk like so. $url …
Chill Web Designs
  • 1,311
  • 2
  • 16
  • 31
0
votes
0 answers

parse_str, parse_url

I've been using parse_url and parse_str in order to get the ?v= from youtube.com links, unfortunatly it seems youtube passes video ID's that begin with both underscores and hyphens. As a result, $url = parse_url($url); $vid =…
Liam Closs
  • 55
  • 1
  • 7
0
votes
1 answer

Determine the current page in PHP within a wordpress plug-in

This issue has been driving me up a wall. I've been working on a mobile website for a friend who uses wordpress. I'm attempting to modify a wordpress plugin that "rethemes" each page for mobile users. I want the plugin to do it's normal thing…
ihake
  • 1,741
  • 1
  • 17
  • 29
-1
votes
2 answers

how to get current url in nextjs without using window.location.href or react router

how to get current url in nextjs without using window.location.href or react router const parse = require("url-parse"); parse("hostname", {}); console.log(parse.href);
-1
votes
1 answer

Is it safe to read a value from an URL with parse_url?

For some reason I can't get the $_GET variable to do anything so I used a work around by just modifying the URL with a string at the end with a ? and reading that into my code with the parse_url function and now I wanted to ask if that is a stupid…
-1
votes
1 answer

Get domains name from full URL

I have a txt file (links.txt) There are thousands of links in it I want to sort all the links using the following code
seyedrezabazyar
  • 89
  • 1
  • 11
-1
votes
2 answers

parse_url replacing the plus sign with a space

$url = parse_url('https://plus.google.com/+erikedgren'); $address = ltrim(rtrim($url['path'], '/'), '/'); echo $address; $address outputs plus.google.com/ erikedgren. Why? And how can I solve this problem? EDIT The code above outputs +erikedgren.…
Airikr
  • 6,258
  • 15
  • 59
  • 110