You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
6 years ago | |
---|---|---|
class | 6 years ago | |
LICENSE | 6 years ago | |
README.md | 6 years ago | |
url-example.php | 6 years ago |
README.md
URL Class
Set of class functions I use from time to time.
- isValidURL - Returns TRUE/FALSE if the string is a Valid URL
- stripWWW - Strips the WWW off the incoming URL
- getDomainName - Strips the WWW off the incoming URL
- Status_Code - Returns the Status Code of a URL ie(200 or 404)
- FavIcon - Get an image object of the FavIcon, Returns (T/F) if present
- Save_FavIcon - Saves the Websites FavIcon to the File/Path
- GetParam - Returns a Form Value
- isMobileDevice - Tests the User Agent to see if it is a mobile device
- isSpiderBot - Tests the User Agent to see if it is a Bot/Spider/Crawler
Quick Example
url-example.php
<?php
// == URL CLASS ==================================
require_once 'class/url.php';
// -- Init Class
$url = new url();
// -- Verify URL (T/F) -------------------------
// Returns a True/False if the URL is valid.
echo ($url->isValidURL('https://www.rick.us') ? 'TRUE' : 'FALSE') . '<br/>';
// -- stripWWW ---------------------------------
// Strips off everything but the domain name.
echo $url->stripWWW('https://www.rhays.us') . '<br/>';
// -- getDomainName ----------------------------
echo $url->getDomainName('https://www.rhays.us') . '<br/>';
// -- Return Status from URL -------------------
// Returns current html status code for site (2xx, 3xx, 4xx, 5xx).
echo $url->Status_Code('https://www.rick.us') . '<br/>';
// -- Does site have a FavIcon (T/F) -----------
// Returns a True/False if site has a favicon present.
echo ($url->FavIcon('https://www.rick.us') ? 'TRUE' : 'FALSE') . '<br/>';
// -- Save and Display favicon Image (T/F) -----
// Saves the favicon as a PNG image to location of your choice.
echo ($url->Save_FavIcon('https://www.rick.us', 'favicon.png') ? 'TRUE' : 'FALSE') . '<br/>';
echo '<img src="favicon.png" alt="FavIcon">';
echo '<br/>';
// -- Display current user agent ---------------
echo $_SERVER['HTTP_USER_AGENT'] . '<br/>';
// -- isMobileDevice ---------------------------
echo ($url->isMobileDevice() ? 'TRUE' : 'FALSE') . '<br/>';
// -- isSpiderBot ------------------------------
echo ($url->isSpiderBot() ? 'TRUE' : 'FALSE') . '<br/>';
// -- Returns the GET/POST param value else returns a default value
$_GET['TEST-GET'] = 'TEST GET';
var_dump($_GET);
echo '<br/>';
$_POST['TEST-POST'] = 'TEST POST';
$_POST['TEST-DEFAULT'] = NULL;
var_dump($_POST);
echo '<br/>';
echo $url->GetParam('TEST-GET', 'No Data') . '<br/>';
echo $url->GetParam('TEST-POST', 'No Data') . '<br/>';
echo $url->GetParam('TEST-DEFAULT', 'DEFAULT') . '<br/>';
// ===================================================
$url = null;