Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
explode and remove end of url
Old 02-03-2009, 01:35 PM explode and remove end of url
Junior Talker

Posts: 5
Name: Lee
Trades: 0
I'm trying to to set the function $request to (in the url) what is after / and minus the last 4 characters. SO if it was mysite. com/red-fish.php gives me "red fish"

This works to explode and remove the dash
PHP Code:
<?php    
$request 
$_SERVER['REQUEST_URI'];    
$request explode('/',$request);    
$_REQUEST['site_search'] = str_replace("-"" "$request[sizeOf($request)-1]); ?>


But I'm not sure how to knock the .php of the end. This didn't work.
PHP Code:
<?php    
$request 
$_SERVER['REQUEST_URI'];    
$request explode('/',$request);    
$request substr($request0, -4);    
$_REQUEST['site_search'] = str_replace("-"" "$request[sizeOf($request)-1]); ?>
jazzylee77 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-03-2009, 01:41 PM Re: explode and remove end of url
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Your code isn't working because you're trying to take the substr of an array. (explode returns an array)

This should work:
PHP Code:
$request $_SERVER['REQUEST_URI'];    
$request strrchr($request,'/');
$request substr($request1, -4); 
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-03-2009, 03:16 PM Re: explode and remove end of url
Junior Talker

Posts: 5
Name: Lee
Trades: 0
Thanks Insensus for pointing out a basic concept I was missing. (Well honestly I was just guessing. Amazing how often that works out for me.) With a bit of other tweaking it's doing the job now.
jazzylee77 is offline
Reply With Quote
View Public Profile
 
Old 02-04-2009, 11:04 PM Re: explode and remove end of url
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
There is a much easier way:

$request = basename($_SERVER['PHP_SELF'], '.php');
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to explode and remove end of url
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.77621 seconds with 12 queries