PHP Classes

Urly: Clean and modify relative or absolute URLs

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 148 All time: 9,108 This week: 673Up
Version License PHP version Categories
urly 1.0GNU General Publi...5.0HTTP, PHP 5, Parsers
Description 

Author

This class can clean and modify relative or absolute URLs.

It can parse a given URL, split it in its parts and store the part values in class variables.

The class can reassemble the parts and return its value as an absolute or relative URL.

Picture of Jake Bown
  Performance   Level  
Name: Jake Bown <contact>
Classes: 3 packages by
Country: United Kingdom
Age: 31
All time rank: 2823130 in United Kingdom
Week rank: 200 Up10 in United Kingdom Up

Example

<?php

/*
 * Cleanup - You can remove all params and return just the domain
 */

require '../urly.php';

$url = 'https://adobe.github.io/Spry/samples/data_region/JSONDataSetSample.html';

$urly = new urly($url, true);
$result = $urly->run();

echo
$result;


?>


Details

Urly

A URL Cleaner for PHP

Variables

<code>$host</code> is the domain (http://www.google.com) <code>$path/$params</code> is the path from the domain (/search?q=Hello+World)

Setup

To get started, you can either view the examples within this repo or copy and paste the code below

<pre> require '../urly.php';

$url = 'YOUR_URL_HERE';

$urly = new urly($url, true); $result = $urly->run(); </pre>

When constructing Urly, you can set the following parameters

<pre>new url([URL], [Hide Path?], [Host]</pre>

If the hide path parameter is set to true, when you run <code>http://example.com/search?hello+world</code> it will return <code>http://www.example.com</code>.

Relative URLs

You can put relative urls into Urly and receive a fully formed url, but you must also set the host so that it can be appended, to do this simple construct Urly like the example below:

<pre> $urly = new urly("/search?hello+world", false, "http://example.com"); //outputs http://example.com/search?hello+world </pre>

Cleaner URLs

If you set the host as <code>google.com</code>, Urly will return <code>http://google.com</code>.

Return Params

If you want to get just the parameters from a URL, simply echo out the variable <code>params</code> like so:

<pre> require '../urly.php';

$url = 'http://www.amazon.com/gp/product/B002FJZLJY?ref_=gbsl_tit_l-1_4822_895d0299&smid=ATVPDKIKX0DER';

$urly = new urly($url); $result = $urly->run();

echo $urly->params; //outputs /gp/product/B002FJZLJY?ref_=gbsl_tit_l-1_4822_895d0299&smid=ATVPDKIKX0DER </pre>


  Files folder image Files (6)  
File Role Description
Files folder imageexamples (4 files)
Accessible without login Plain text file README.md Doc. Documentation
Plain text file urly.php Class Class source

  Files folder image Files (6)  /  examples  
File Role Description
  Accessible without login Plain text file cleanup.php Example Example script
  Accessible without login Plain text file incomplete.php Example Example script
  Accessible without login Plain text file params.php Example Example script
  Accessible without login Plain text file relative.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:148
This week:0
All time:9,108
This week:673Up