PHP code example of ismaxim / urling

1. Go to this page and download the library: Download ismaxim/urling library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ismaxim / urling example snippets


# Url parser mode

use Urling\Urling;

$urling = new Urling("https://github.com/ismaxim/urling#start");

$url_part_values = [
    "protocol_value" => $urling->url->protocol->get(),
    "domain_value"   => $urling->url->domain->get(),
    "routes_value"   => $urling->url->routes->get(),
    "anchor_value"   => $urling->url->anchor->get(),
];

print_r($url_part_values);

/* 
    RESULT: 

    [
        "protocol_value" => "https",
        "domain_value"   => "github.com",
        "routes_value"   => "ismaxim/urling",
        "anchor_value"   => "start",
    ] 
*/

# Url constructor mode

use Urling\Urling;
        
$urling = new Urling();

$urling->url->construct([
    "protocol" => "https",
    "domain"   => "github.com",
    "routes"   => "ismaxim/urling",
    "anchor"   => "start",
]);

// Either you can set the value for each distinct part 
// in the url by accessing it directly, for example:

$urling->url->protocol->add("https");
$urling->url->domain->add("github.com");
$urling->url->routes->add("ismaxim/urling");
$urling->url->anchor->add("start");

print_r($urling->url->get());

/* 
    RESULT:
    
    "https://github.com/ismaxim/urling#start"
*/

$urling->url->scheme->... | $urling->url->protocol->... (other parts of url in a similar way).

// Working with URL

$urling->url->add();
$urling->url->get();
$urling->url->update();
$urling->url->delete();

// Working with one of the URL parts

$urling->url->scheme->add();
$urling->url->scheme->get();
$urling->url->scheme->update();
$urling->url->scheme->delete();

// For example, let's imagine that the URL is: https://github.com/ismaxim/urling#basic-usage
// Then example workflow to parse this URL in part of "scheme" or "protocol" (see ACCESSING TABLE, column "Aliases") will seem to this:

$urling->url->scheme->get();          # returns "https" (state of URL: https://github.com/ismaxim/urling#basic-usage)
$urling->url->scheme->delete();       # returns null    (state of URL: github.com/ismaxim/urling#basic-usage)
$urling->url->scheme->add("ftp");     # returns "ftp"   (state of URL: ftp://github.com/ismaxim/urling#basic-usage)
$urling->url->scheme->update("smtp"); # returns "smtp"  (state of URL: smtp://github.com/ismaxim/urling#basic-usage)

// Work with other parts of URL can be done in a similar way.

$urling->url->params->getValueByName();
$urling->url->params->getNameValuePairs();

$urling->url->params->get()