Page 1 of 1
Shortening URLs
Posted: Sat Apr 27, 2002 8:55 pm
by SpaceManSpiff
How can I have PHP cut off anything after the 50th character of a variable?
Say I have...
Code: Select all
$url = "http://dir.yahoo.com/Business_and_Economy/Shopping_and_Services/Photography/Photojournalism/";
How can I get the URL shortened into like the first 50 characters so that I can do something like..
Code: Select all
<a href="http://dir.yahoo.com/Business_and_Economy/Shopping_and_Services/Photography/Photojournalism/">http://dir.yahoo.com/Business_and_Economy/Shopp...</a>
------
<a href="$url">$urlshort</a>
Posted: Sat Apr 27, 2002 9:05 pm
by Gamefreak
Ok, here's how you do it:
Code: Select all
$full_url = "this.really/long/url/";
if (strlen($full_url)>=50) {
$short_url = substr(%full_url, 0, 50);
$short_url .= "...";
}
Your url will have the "..." on the end only if it is 50 characters or longer. Hope this helps you!
Posted: Sat Apr 27, 2002 9:07 pm
by SpaceManSpiff
That's exactly what I wanted. Thanks!

Posted: Tue Aug 06, 2002 6:34 pm
by learning_php_mysql
is their anyway to get the url directly from the addressbar?
Posted: Tue Aug 06, 2002 8:32 pm
by fatalcure
yea:
Code: Select all
echo $_SERVERї"HTTP_HOST"]$SERVERї"REQUEST_URI"];

Posted: Tue Aug 06, 2002 11:39 pm
by learning_php_mysql
sweet, is there a way to like take that then format it then plug something else into the address bar?
Posted: Wed Aug 07, 2002 6:55 pm
by fatalcure
yea,
Code: Select all
$currentURL = $SERVERї"HTTP_HOST"]$SERVERї"REQUEST_URI"];
//code to alter the currentURL - set variable $newURL
header("Location: $newURL");
Posted: Wed Aug 07, 2002 10:04 pm
by learning_php_mysql
i meant is tehre a way to make the url look different?
Posted: Wed Aug 07, 2002 10:10 pm
by fatalcure
what do u mean exactly? what URL are u talking about?
Posted: Wed Aug 07, 2002 10:21 pm
by learning_php_mysql
lets say my website is at
http://www.site.com
i have an admin cp and lets say its files are in
http://www.site.com/acp/
is there a way to make the url in the address bar look like
http://www.site.com...
?
thanks