homepage Welcome to WebmasterWorld Guest from 54.226.136.179
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Editing a string
whatson

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4457228 posted 6:23 am on May 24, 2012 (gmt 0)

If I have e.g. 'category.php'
what is the best way to create a variable of just
$variable = 'category'?

Do I have to explode and implode it?

 

Andy Langton

WebmasterWorld Senior Member andy_langton us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4457228 posted 11:15 am on May 24, 2012 (gmt 0)

A bit more info would help :)

Usually you would pass URL parameters via GET, perhaps handled by your app index file, e.g.

/index.php?type=category

You might then use a switch statement [php.net] to decide what to do based on the 'type'.

However, if you simply want to grab the 'name' of a PHP file, I would use regex:

<?php
# get the filename = REQUEST_URI is also an option, but maybe less secure?
$filename=$_SERVER['SCRIPT_FILENAME'];
# match the part before .php
preg_match('#.*/([^\.]+).php$#',$filename,$matches);
$filename_part=$matches[1];
# test output
echo "<h1>$filename_part</h1>";
?>


I'm no PHP guru though!

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4457228 posted 3:59 pm on May 24, 2012 (gmt 0)

It also might be more helpful to describe **why** you need to do this, often there are solutions found different than the one you've chosen.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved