PHP : Converts double slashes in a string to a single slash

In this tutorial learn how to Converts double slashes in a string to a single slash, except those found in http:// ,

http://www.example.com//index.php 

becomes: 

http://www.example.com/index.php

Tutorial

<?php
    /**
  * Reduce Double Slashes
  *
  * Converts double slashes in a string to a single slash,
  * except those found in http://
  *
  * http://www.example.com//index.php
  *
  * becomes:
  *
  * http://www.example.com/index.php
  *
  * @param string
  * @return string
  */
 function reduce_double_slashes($str)
 {
  return preg_replace('#(^|[^:])//+#', '\\1/', $str);
 }
 
 echo reduce_double_slashes("http://www.example.com//index.php");
 ?>
About Tutorial Output

http://www.example.com/index.php

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...