Current location: Hot Scripts Forums » Programming Languages » PHP » Remove slash


Remove slash

Reply
  #1 (permalink)  
Old 04-23-04, 08:41 AM
Eznetlinks Eznetlinks is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Remove slash

I'm writing a script that uses $_SERVER["PHP_SELF"]. The output results in /page.php. I need to remove the "/" so output is page.php. How do i remove the slash ("/").

Thanks,
Eznetlinks
Reply With Quote
  #2 (permalink)  
Old 04-23-04, 09:03 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
it is not a problem to have this slash ..but
PHP Code:

str_replace('/'''$_SERVER['PHP_SELF']); 

but if you have your script not running on the root then you will have problem since it will work like this if it was on a sub directory :
PHP Code:

//assume that you are running on a dir called dir1

//and your file is filename1
//so $_SERVER['PHP_SELF'] will give /dir1/filename1.php
echo str_replace('/'''$_SERVER['PHP_SELF']); //will print dir1filename.php !! 
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 04-23-04, 09:17 AM
Eznetlinks Eznetlinks is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks that will do the job. I needed it to make this text counter.

<?
$root = $_SERVER["DOCUMENT_ROOT"];
$counid = $_SERVER["PHP_SELF"];
$counid = str_replace('/', '', $counid);
if(is_dir("$root/counters"))
{
if (is_file("$root/counters/$counid.txt")){
$datei = fopen("$root/counters/$counid.txt","r");
$count = fgets($datei,1000);
fclose($datei);
$count=$count + 1 ;
echo "<font face=Arial, Helvetica size=2>You Are Vistor # $count</font><br>" ;
echo "\n<br>" ;
$datei = fopen("$root/counters/$counid.txt","w");
fwrite($datei, $count);
fclose($datei);
}else{fopen("$root/counters/$counid.txt","w");
header("Location: /$counid");}}
else{mkdir("$root/counters");
header("Location: /$counid");
}
?>

count visits to individual pages keeps all counters in one file.

Thanks,
Eznetlinks

Last edited by Eznetlinks; 04-23-04 at 09:43 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 10:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.