EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

PHP URL

Home » Software Development » Software Development Tutorials » PHP Tutorial » PHP URL

PHP URL

Definition of PHP URL

Generally, the URL means Uniform Resource Locater. Likewise, URL in PHP Programming Language is also the same. URL is nothing but a website address. It helps in connecting the client and the server when browsed using a specific link. URL looks simple but it contains specific info of the specific website address which actually points to a specific IP Address which actually points to a specific domain hosting. This PHP URL also has many URL functions to handle which are useful in handling the URL like encoding, decoding, parsing, etc. based on our requirement. Usually, there will be two types of URLs. They are HTTPS enabled URLs and HTTPS disabled URLs which are shown in the below syntax. Check out the below content so that you will understand the whole concept of the PHP URL concept in detail.

Syntax and Parameters

Syntax and parameters of php url is given below:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

https://www.educba.com
http://www.profitloops.in

Explanation of the PHP URL Parameters:

  • https and http parameter: This is the parameter that represents whether the URL is HTTPS enabled or HTTP enabled. HTTP means Hyper Text Transfer Protocol whereas HTTPS means Hyper Text Transfer Protocol Secured.
  • www parameter: This parameter is a normal parameter for any time of the website URL before the domain name. WWW means the World Wide Web.
  • domain name parameter and domain extension: The domain name parameter is the name of the specific website and it will end with some domain extension like .com or .biz or .in or .us etc. The “.COM” is normal for many websites but if the extension ends with “.IN” that means it belongs to Indian Country Domain like. “. The US” is for US Domains, “.BIZ” is for Business Domains etc..

How URL Works in PHP?

In any web programming language which are like PHP Programming Language, whenever a user enters a specific URL in the URL section of the browser then that request will be passed to the specific domain name server. Then the domain server will return to a specific assigned IP Address and proceeds to the hosting server which hosts a blog/website. Then browser like Educba Chrome/any other request a specific page from the specific web server with the help of the IP Address which is actually specified by the domain name server. Then that web server will return the page to a specific IP Address which is actually specifying by the specific browser which is actually requesting the page. That specific page that appeared in front of you on the browser may contain many other URL’s which may contain many server pages, many images, etc. The URL can be anything like www.educba.com or any other like that.

URL Function in PHP:

There are different types of URL Functions that help in dealing with the URL strings. The URL is an address that is helpful in identifying a specific website and that URL string text may appear like:https://freeforts.blogspot.com/2017/01/download-youtube-clone-template-for.html. Here I used some BlogSpot sub domain. Some of the URL Functions include.

  • get_headers()
  • get_meta_tags()
  • parse_url()
  • urlencode()
  • urldecode()
  • rawurlencode()
  • rawurldecode()

1. get_header() URL Function

The get_header() URL Function helps in fetching all headers which are actually sent by the specific server in response to the HTTP request/requests.

Example

This is the example of illustrating the get_headers() function which helps in fetching all the headers which are actually sent by the specific server as a response for HTTP request/requests. Here I am using http://www.educba.com as an URL input. Here we will get all headers of that specific URL. Syntax:

<?php
$url = 'http://www.educba.com';
print_r(get_headers($url));
?>

Output:

PHP URL-1.1

2. get _meta_tags() URL Function

The get_meta_tags() URL Function helps in extracting all the meta tag content data attributes which are from the file which returns a specific array.

Popular Course in this category
PHP Training (5 Courses, 3 Project)5 Online Courses | 3 Hands-on Project | 28+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,726 ratings)
Course Price

View Course

Related Courses
Java Servlet Training (6 Courses, 12 Projects)All in One Software Development Bundle (600+ Courses, 50+ projects)
Example

This is the example of illustrating the get_meta_tags() URL function to get all meta tag attibutes of the specific input URL. Here only the home page URL is used so there will be no meta tags and this will shown as empty inside of the array.

<?php
$url = "https://www.educba.com/";
$metas = get_meta_tags($url);
print_r($metas);
?>

Output:

PHP URL-1.2

3. parse_url() URL Function

The parse_url() URL Function helps in parsing the URL and helps in returning its components.

Example

This is the example of parsing a specific input URL based on our requirements. Here we are parsing the http://www.educba.com URL. Check out the output so that you will get how the input URL is parsed.

<?php
$url = 'http://www.educba.com';
var_dump(parse_url($url));
?>

Output:

PHP URL-1.3

4. urlencode() URL Function

The urlencode() URL Function helps in encoding the URL.

Example

This is the example of illustrating urlencode() URL function. Here I used four different types of URL’s. With the help of urlencode() URL Function, each and every URL will be encoded into different types but string type only. You can check the output so that you will under how different types of URL’s are encoded. <br> tags with echo statement just to display line breaks and <hr> tags are used to display horizontal lines when the syntax is executed.

<?php
// This is the PHP program of illustrating the urlencode functionality
echo urlencode("https://www.educba.com") . "\n";
echo urlencode("http://www.profitloops.in/") . "\n";
echo urlencode("https://profitloops.wordpress.com/") . "\n";
echo urlencode("https://freeforts.blogspot.com/") . "\n";
?>

Output:

PHP URL-1.4

5. urldecode() URL Function

The urldecode() URL Function helps in decoding the encoded URL.

Example

This is the example of illustrating the urldecode() URL function. In order to decode the URL, we need the already encoded code that means the specific input URL or URL’s of urldecode() should be the output of urlencode() function. Here I used the encoded urls of the outputs of the above example. Then after the execution, you will get the above example’s inputs. Check out the outputs so that you will know how the decode function is working.

<?php
//This is the program of illustrating URL Decode() function of PHP
echo urldecode("https%3A%2F%2Fwww.educba.com");
echo "\n";
echo urldecode("http%3A%2F%2Fwww.profitloops.in%2F");
echo "\n";
echo urldecode("https%3A%2F%2Fprofitloops.wordpress.com%2F");
echo "\n";
echo urldecode("https%3A%2F%2Ffreeforts.blogspot.com%2F");
echo "\n";
?>

Output:

Output-1.5

6. rawurlencode() URL Function

The rawurlencode() URL Function helps in encoding the URL according to the RFC 1738.

Example

This is the example of illustrating the rawurlencode() function. Here with the help of the rawurlencode() function, only the string will be encoded for the specific URL.

<?php
echo '<a href="www.educba.com',
rawurlencode('A Multi Info Portal for Bloggers'), '">';
?>

Output:

Output-1.6

7. rawurldecode() URL Function

The rawurldecode() URL Function helps in decoding the URL which is decoded according to the RFC 1738.

Example

This is the example of decoding the rawurlencode() inputs. Check out the above example and this example so that you will understand what is happening and also check out the outputs.

<?php
echo rawurldecode('A%20Multi%20Info%20Portal%20for%20Bloggers');
?>

Output:

Output-1.7

Recommended Articles

This is a guide to PHP URL. Here we also discuss the introduction and how url works in php along with its different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. PHP Split Array
  2. PHP include_once
  3. PHP Array Search
  4. PHP GET Method

PHP Training (5 Courses, 3 Project)

5 Online Courses

3 Hands-on Project

28+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PHP Tutorial
  • Functions
    • Functions in PHP
    • PHP Math Functions
    • PHP Recursive Function
    • PHP String Functions
    • Hashing Function in PHP
    • Date Function in PHP
    • PHP Anonymous Function
    • Calendar in PHP
    • PHP Call Function
    • PHP Pass by Reference
    • PHP ucfirst()
    • PHP ucwords()
    • trim() in PHP
    • isset() Function in PHP
    • PHP replace
    • PHP fpm
    • PHP strpos
    • preg_match in PHP
    • PHP preg_replace()
    • PHP ob_start()
    • PHP Reflection
    • PHP Split String
    • PHP URL
    • PHP preg_match_all
    • PHP strtoupper()
    • PHP preg_split()
    • PHP substr_replace()
    • PHP setlocale()
    • PHP substr_count()
    • PHP Serialize
    • PHP strlen()
    • PHP async
    • PHP Date Time Functions
    • PHP timezone
    • PHP Data Object
    • print_r() in PHP
    • PHP header()
    • PHP strip_tags()
    • PHP chop()
    • PHP MD5()
    • PHP unset()
    • PHP crypt()
    • PHP wordwrap()
    • PHP is_null()
    • PHP strtok()
    • PHP bin2hex()
    • PHP parse_str()
    • PHP levenshtein()
    • PHP addslashes()
    • PHP strtotime
    • PHP sha1()
    • PHP explode()
    • PHP sscanf()
    • PHP require_once
    • PHP Zip Files
    • PHP $_SERVER
    • PHP $_POST
    • PHP Include and Require
    • PHP POST Method
  • PHP Basic
    • Introduction To PHP
    • What is PHP
    • PHP Keywords
    • Advantages of PHP
    • Career In PHP
    • Comments in PHP
    • PHP Commands
    • PHP Frameworks
    • PHP Compiler
    • Variables in PHP
    • PHP Superglobal Variables
    • PHP Versions
    • Object in PHP
    • What is Drupal
    • Top PHP Frameworks
    • WebStorm IDE
    • What is phpMyAdmin?
    • PhpStorm
    • Install phpMyAdmin
    • Phalcon Model
  • Data Types
    • PHP Data Types
    • PHP Integer
    • PHP Booleans
  • Operators
    • PHP Operators
    • Arithmetic Operators in PHP
    • Comparison Operators in PHP
    • Logical Operators in PHP
    • Bitwise Operators in PHP
    • Ternary Operator in PHP
    • PHP String Operators
  • Control Statements
    • Control Statement in PHP
    • PHP if Statement
    • if else Statement in PHP
    • elseif in PHP
    • PHP Switch Statement
    • Continue in PHP
    • Break in PHP
  • Loops
    • PHP Loops
    • For Loop in PHP
    • PHP Do While Loop
    • PHP While Loop
    • While Loop in PHP
    • Foreach Loop in PHP
  • Constructor
    • Constructor in PHP
    • Destructor in PHP
  • State Management
    • Cookie in PHP
    • Sessions in PHP
  • Array
    • What is PHP Array
    • Arrays in PHP
    • 2D Arrays in PHP
    • Associative Array in PHP 
    • Multidimensional Array in PHP
    • Indexed Array in PHP
    • PHP Array Functions
    • PHP unset Array
    • PHP Append Array
    • PHP Array Search
    • PHP Split Array
    • PHP array_push()
    • PHP array_pop()
  • Advanced
    • Overloading in PHP
    • Overriding in PHP
    • Method Overloading in PHP
    • Inheritance in PHP
    • Multiple Inheritance in PHP
    • PHP Interface
    • Encapsulation in PHP
    • PHP Constants
    • PHP Magic Constants
    • PHP Regular Expressions
    • PHP GET Method
    • PHP Annotations
    • PHP Encryption
    • PHP file Functions
    • PHP readfile
    • PHP?Write File
    • PHP Append File
    • PHP Type Hinting
    • PHP Filters
    • PHP Float
    • PHP Form
    • PHP Form Validation
    • Sorting in PHP
    • PHP usort()
    • PHP Stack Trace
    • PHP Stack Overflow
    • PHP Pagination
    • PHP implode
    • Polymorphism in PHP
    • Abstract Class in PHP
    • PHP Final Class
    • PHP Custom Exception
    • error_reporting() in PHP
    • PHP Log Errors
    • Access Modifiers in PHP
    • PHP Change Date Format
    • Static Method in PHP
    • PHP File Handling
    • PHP Output Buffering
    • Get IP Address in PHP
    • Upload a File in PHP
    • String in PHP
    • Public Function in PHP
    • Private in PHP
    • Protected in PHP
    • basename in PHP
    • Validation in PHP
    • PHP mail()
    • PHP Email Form
    • PHP Directory
    • PHP Create Session
    • PHP include_once
    • PHP json_decode
    • PHP XMLWriter
    • PHP XML Reader
    • PHP XML Parser
    • PHP XML into Array
    • Phalcon Framework
  • Programs
    • Patterns in PHP
    • Star Patterns in PHP
    • Swapping in PHP
    • Fibonacci Series PHP
    • Factorial in PHP
    • Reverse String in PHP
    • Square Root in PHP
    • Random Number Generator in PHP
    • Palindrome in PHP
    • Prime Numbers in PHP
    • Armstrong Number in PHP
    • Socket Programming in PHP
    • Login Page in PHP
    • PHP Login Template
    • PHP Object to String
  • Database
    • PHP Database Connection
    • How to Connect Database to PHP
  • Interview Questions
    • PHP Interview Questions
    • PHP OOP Interview Questions
    • CakePHP Interview Questions
    • Core PHP Interview Questions

Related Courses

PHP Training Course

Java Servlet Training

Software Development Course Training

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - PHP Training (5 Courses, 3 Project) Learn More