Advertisement
Guest User

regexp

a guest
Jan 27th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2.     $port = 22003; // Define a default port to follow
  3.    
  4.     function stripAddress($address) {
  5.         $strip_address = preg_replace("/[^A-Za-z0-9.-:]/", "", str_replace("mtasa://", "", $address)); // Take out the mtasa:// protocol from the address and remove any unwanted characters
  6.         $straps = preg_split("/:/", $strip_address); // Strip all beginnings with a colon
  7.         $strip = preg_replace("/[^0-9]/", "", $straps[count($straps)-1]); // Take the latter colon ending and strip everything that isn't a number
  8.         if (strlen($strip) > 1) { $port = (integer)$strip; } // Re-define the default port with the new one
  9.         $strip_address = str_replace((string)$port, "", preg_replace("/[^A-Za-z0-9.-]/", "", $strip_address)); // Take out the port number from the full address and remove any unwanted characters again
  10.         return '<a href="mtasa://' . $strip_address . ':' . $port . '">mtasa://' . $strip_address . ':' . $port . '</a>'; // Glue the protocol, address and port
  11.     }
  12. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement