URL

File name sanitizer

This is a way to sanitize a string to be used as file name or URL path etc. by removing unwanted characters or replacing them with a hyphen or similar.
It takes a string like:
Daily SimpliVity Backup 12/16/2018 02:00:215
and converts it into:
daily-simplivity-backup-12-16-2018-02-00-25

Clean up URL with parse_url

Clean up URL.s with parse_url() by:

* add "http://" if scheme is missing

* add correct "glue" (://) between scheme and host

<?php
$parse
= parse_url($url);

if (empty(
$parse['scheme'])) {
   
$url = "http://".$url;
}else{
   
$url = $parse['scheme']."://".$parse['host'].$parse['path']. (!empty($parse['query']) ? "?".$parse['query'] : "") . (!empty($parse['fragment']) ? "#".$parse['fragment'] : "");
}
?>

Clean up an URL from scripts

<?php
function clean_url(&$hit_link) {
// Find the first occurency of "http://". If it's not at position zero remove everything before it.
   
$find = 'http://';
   
$url  = $hit_link;
   
$pos  = strpos($url, $find);

    if(
$pos !== FALSE) {
     
// We found a http://, on what position?
     
if($pos > 0) {
       
$pos += 7;
       
$url = substr($url, $pos); //Removes the first "http://"
       
$hit_link = $url;
      }
    }
  }
?>

Add bulk generate URL alias via pathauto function

If you have access to your own module you can add a hook_cron function with the following code. On each cron it will execute the bulk generation for nodes

<?php
function feed_control_cron(){
   
   
//If you want to change the number of nodes to change
   
variable_set('pathauto_max_bulk_update', 1000);
   
   
//include the .inc files of pathauto
   
_pathauto_include();

   
//Executes the generation of URL aliases for nodes
   
node_pathauto_bulkupdate();
}
?>

Other solutions: http://drupal.org/node/236304

Validate URL by regular expression

This is how you can validate an URL by examining the pattern.

<?php
function  validateURL($url) {
 
$pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&amp;?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/';
 return
preg_match($pattern, $url);
}
?>

Or from Drupal 6

/**
* Verify the syntax of the given URL.
*
* This function should only be used on actual URLs.

Check if URL exist

This function checks if a given URL is valid by using fsockopen.


function is_valid_url ($url){
$url = @parse_url($url);
if ( ! $url) {
return false;
}

$url = array_map('trim', $url);
$url['port'] = (!isset($url['port'])) ? 80 : (int)$url['port'];
$path = (isset($url['path'])) ? $url['path'] : '';

if ($path == ''){
$path = '/';
}

$path .= ( isset ( $url['query'] ) ) ?