I would like to use this script <?php echo $_SERVER['REQUEST_URI']; ?> This script shows the url of the page that it is on For example Untitled4.php would be shown in the page Is there something i can do to the script to minus the .php bit so it just shows the Untitled4 ?
You might want to buy a PHP book PHP has excellent string manipulation functions. So... $full_uri = $_SERVER['REQUEST_URI']; $what_you_want = substr($full_uri, -4); //check this with php.net PHP:
What you do with it? I don't know, you asked for it! Use it for whatever you wanted to use it. BTW better would be, if there is only one dot: $uri_parts = explode(".", $full_uri); $what_you_want = $uri_parts[0]; PHP:
OK i made a new page just to test that out this is my page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/JavaScript"> <!-- function $uri_parts = explode(".", $full_URI); $what_you_want = $uri_parts[0]; //--> </script> </head> <body><?php echo $_SERVER['REQUEST_URI']; ?> </body> </html> PHP: and the link to that page to view it is here Http://www.geekazoid.co.uk/Untitled-4.php As you can see the .php at the end is still there. Any Ideas ?
No offense but I think it's time for that book # <script type="text/JavaScript"> # <!-- # function # $uri_parts = explode(".", $full_URI); # $what_you_want = $uri_parts[0]; # //--> # </script> Code (markup): That means nothing. What has JavaScript got to do with it? What is that 'function'? You used $full_URI in the explode funtion. But look at the lines preceding it... It never gets initiated. You forgot this line: $full_uri = $_SERVER['REQUEST_URI'];
Im not affended, Im merely asking for help. So can you show me how i should use the script you have given
<?php $full_uri = $_SERVER['REQUEST_URI']; $uri_parts = explode(".", $full_uri); $what_you_want = $uri_parts[0]; echo $what_you_want; ?> PHP: Expected result on http://www.geekazoid.co.uk/Untitled-4.php Doesn't work with folders...
Thanx alot, And i will take you advice and purchase a book. Theres a lot i need to learn and i suppose i cant keep relying on the kind people here. Thanx
You might find members crazy enough to keep pasting you working code but it's not a viable solution for yourself long-term. If this stuff interests you, yeah I'd go get a book or do some tutorials online. If it's not something you fancy doing, then get an account a get-a-freelancer and build a relationship with a trusted coder. For everything in between, there's us geeks ready for you
Thanx alot its working now, http://www.geekazoid.co.uk/Untitled-4.php Im sorry to ask again but is there any way to get rid of the / in front of the url ? If this is a big job then dont worry i will go read up about it. Thanx for your help
It's a massive job... $what_you_really_want = substr($what_you_want, 1); PHP: EDIT: I can see the next question coming so here's the answer: <?php $full_uri = $_SERVER['REQUEST_URI']; $uri_parts = explode(".", $full_uri); $what_you_want = $uri_parts[0]; $what_you_really_want = substr($what_you_want, 1); echo $what_you_really_want; ?> PHP:
Thankyou Very Much, The Script Is Working Perfectly ok i would love to be as in the know about php as you, Do you know of any good beginer tutorials ?
http://www.amazon.com/gp/product/07...0605/ref=pd_bbs_2/002-9109729-0831268?ie=UTF8 That's what got me up to speed. And php.net + phpfreaks.com, sitepoint.com and some other random places.
I learnt everything I know from google. Type what you want to do into the search box and 9 times out of 10 you get an answer. Also like T0PS says follow a few tutorials to get the hang of it. Most things in php have been done before so you may get lucky and just find something you can cut and paste.
I would suggest using dirname() and basename() respectively. basename() will give the name of the script but also has the benefit of being able to mask the extension given the second optional parameter. Here is a short example: <?php /** * URL Parts Test Script * * Short example created for geekazoid from DP forum * * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0 * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers * @copyright Copyright 2006, Bobby Easland * @author Bobby Easland */ /** * Function to get the script name from path string * @author Bobby Easland * @version 1.0 * @param string $script * @param string $extension * @return string */ function getScriptNameMinusExtension($script, $extension = '.php'){ return basename($script, $extension); } # end function /** * Function to get the directory name from path string * @author Bobby Easland * @version 1.0 * @param string $path * @return string */ function getDirName($path){ return dirname($path); } # end function ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>URL Parts Test Script</title> </head> <body> <!-- Output the directory name //--> <p>Directory Name: <?php echo getDirName($_SERVER['SCRIPT_NAME']); ?></p> <!-- Output the script name //--> <p>Script Name: <?php echo getScriptNameMinusExtension($_SERVER['SCRIPT_NAME'], ''); ?></p> <!-- Output the script name minus the PHP extension //--> <p>Script Name (minus extension): <?php echo getScriptNameMinusExtension($_SERVER['SCRIPT_NAME']); ?></p> </body> </html> PHP: Bobby