PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
SpaceManSpiff
Forum Newbie
Posts: 6 Joined: Sat Apr 27, 2002 8:55 pm
Post
by SpaceManSpiff » Sat Apr 27, 2002 8:55 pm
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>
Gamefreak
Forum Newbie
Posts: 1 Joined: Sat Apr 27, 2002 9:05 pm
Post
by Gamefreak » Sat Apr 27, 2002 9:05 pm
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!
SpaceManSpiff
Forum Newbie
Posts: 6 Joined: Sat Apr 27, 2002 8:55 pm
Post
by SpaceManSpiff » Sat Apr 27, 2002 9:07 pm
That's exactly what I wanted. Thanks!
fatalcure
Forum Contributor
Posts: 141 Joined: Thu Jul 04, 2002 12:57 pm
Contact:
Post
by fatalcure » Tue Aug 06, 2002 8:32 pm
yea:
Code: Select all
echo $_SERVERї"HTTP_HOST"]$SERVERї"REQUEST_URI"];
learning_php_mysql
Forum Commoner
Posts: 27 Joined: Sun Aug 04, 2002 12:58 pm
Location: WA
Post
by learning_php_mysql » Tue Aug 06, 2002 11:39 pm
sweet, is there a way to like take that then format it then plug something else into the address bar?
fatalcure
Forum Contributor
Posts: 141 Joined: Thu Jul 04, 2002 12:57 pm
Contact:
Post
by fatalcure » Wed Aug 07, 2002 6:55 pm
yea,
Code: Select all
$currentURL = $SERVERї"HTTP_HOST"]$SERVERї"REQUEST_URI"];
//code to alter the currentURL - set variable $newURL
header("Location: $newURL");
fatalcure
Forum Contributor
Posts: 141 Joined: Thu Jul 04, 2002 12:57 pm
Contact:
Post
by fatalcure » Wed Aug 07, 2002 10:10 pm
what do u mean exactly? what URL are u talking about?