PHP Snippet: Display Last X Characters of a URL

Had a request to return the last 23 characters of a url. I am WAY not a coder, but was able to help modify this function to work. Of course, you probably won’t just want to echo the output, but use it as a variable for something else.

<?php function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
 }
 echo substr(curpageURL(),-23);?>
Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *