|
 |
|
 |
10-21-2004, 06:06 PM
|
#16 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
Hey sde!! Yeah sorry man I've been hard at work on coding and working my butt off being my bar in town.
I now code php for monies on a freelance agency website
Anyway (you spammer, you) what the hell does the basename() function do? Please don't make me cope with the php.net manual again, please!
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
10-21-2004, 08:28 PM
|
#17 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
well take this advice from me. i've been coding php for around 5 years and this is the best words of wisdom i can give you ...
... the php manual is your friend!
not only does it have an explanation of the function, but it has examples, and a list of other functions like it on the left.
on top of that, the function search works great!
now for basename()
Given a string containing a path to a file, this function will return the base name of the file. If the filename ends in suffix this will also be cut off.
On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).
PHP Code:
<?php
$path = "/home/httpd/html/index.php";
$file = basename($path); // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
?>
does that make sense?
__________________
Mike
|
|
|
10-22-2004, 02:51 AM
|
#18 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
Oh wow that makes some other jobs I've been working on so much easier!!
That means I can place scripts in any dir - if I use basename then it will work regardless. You probably have no idea how long I'v been looking for a way to do that. I've tried exploding PHP_SELF. tried using javascript ...oh God the headaches..!!
Thank You 
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
10-22-2004, 07:38 AM
|
#19 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
don't thank me, thank php.net =)
http://us2.php.net/manual/en/function.basename.php
it was a trick! i copied the explanation word for word and the example was from that page too!
that is my point, php.net is your friend. all i did was type 'basename' and hit search. 
__________________
Mike
|
|
|
10-22-2004, 04:02 PM
|
#20 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
Haha! You bugger!
The embaressing thing was I even have the manual in CHM format and I actually...use it quite alot. Just sometimes a 'normal' person explaining things can be alot more effective then having to read a technical piece / manual.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
10-22-2004, 04:35 PM
|
#21 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
ah, totally understand. i actually used to not look at it much and would prefer books. now it's pretty much all i reference.
__________________
Mike
|
|
|
10-23-2004, 01:42 AM
|
#22 (permalink)
|
|
PHP Student
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 151
|
It looks like you've gotten a few very good replies. I thought I'd show you how I handle the process you're talking about.
The following code is my index.php, I'll do my best to explain what the code is doing, it's really pretty simple.
PHP Code:
<?php
session_start(); //Initialize a PHP session
include 'includes/functions.php'; //Include some custom functions for the site
av_init(); //This initiates some common variables including template paths, and scans the users IP against my BAN list
include $tpl_path . 'header.php'; //$tpl_path is the path of the current template for the website.
include $tpl_path . 'navbar.php'; //I am including this templates header and navigation bar
insert_banner(0, 'center'); //another custom function to insert a random banner from a list in a MySQL table
echo '<br><br>';
/**** HERE IS THE MEAT OF THE CODE ****/
$page = $_GET['page'];
switch ($page) {
case 'viewprofile':
include $tpl_path . 'profile.php';
break;
case 'status':
include $tpl_path . 'server.php';
break;
case 'csphotos':
include $tpl_path . 'oops.php';
break;
case 'apply':
include $tpl_path . 'recrute.php';
break;
case 'contactus':
include $tpl_path . 'contactus.php';
break;
case 'process':
include 'includes/process_recrute.php';
include $tpl_path . 'application_complete.php';
break;
case 'lan2005':
include $tpl_path . 'lan2005.php';
break;
case 'mail_form';
include $tpl_path . 'mail_form.php';
break;
case 'sendmail';
include 'includes/sendmail.php';
include $tpl_path . 'email_complete.php';
break;
default:
insert_news(5, 500, 15);
}
include $tpl_path . 'footer.php';
?>
In the "MEAT" of the code, you'll see I take the "page" URL variable and enter it into a "SWITCH" statement. I use that "page" variable to include the requested content. Doing this I am able to create unlimited numbers of pages without having to copy/paste the same headers and footers over and over. Every page on my website runs through index.php. I realise now that I can save a lot of lines of code by setting the page value to the actual filename and running that through one simple expression, though that wouldn't allow me to run page specific routines when needed, like when $page = process/sendmail
|
|
|
10-23-2004, 02:37 PM
|
#23 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
Ooh that's given me some great ideas for a script I'm working on for a client! Thank you!
I'm just interested to know about your news function. Could you paste it to me? PM if you would rather?
PHP Code:
insert_news(5, 500, 15)
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
10-23-2004, 04:04 PM
|
#24 (permalink)
|
|
PHP Student
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 151
|
Sure thing, here is my insert_news() function straight from my website
PHP Code:
function insert_news($num_threads, $width, $margin)
{
global $root, $tpl_name, $tpl_path, $forum_path, $max_news;
$query = "SELECT topic_first_post_id, topic_poster, topic_time, topic_id FROM phpbb_topics WHERE forum_id = '6' ORDER BY topic_time DESC";
$result = mysql_query($query) or die("Error: ".mysql_error());
$num_rows = mysql_affected_rows();
if ($max_news > $num_rows || $num_threads == 0)
$x = $num_rows;
else
$x = $max_news;
for ($i = 1; $i <= $x; $i++)
{
$post[$i] = mysql_fetch_row($result);
}
$i = 0;
foreach($post as $value)
{
$i++;
$post_id = $value[0];
$topic_id = $value[3];
$query = "SELECT post_subject, post_text FROM phpbb_posts_text WHERE post_id = '".$post_id."'";
$result = mysql_query($query) or die("ERROR: ".mysql_error());
$data = mysql_fetch_row($result);
$news_subject = $data[0];
$news_text = $data[1];
$post_time = $post[$i][2];
$query = "SELECT username FROM phpbb_users WHERE user_id = '".$post[$i][1]."'";
$result = mysql_query($query);
$data = mysql_fetch_row($result);
$poster = $data[0];
include $tpl_path . "news.php";
}
}
This function pulls $max_news threads from the top of my websites News forum. It then parses the information for that post and posts it on the index of my website with a dynamically created background for each post. $max_news is an integer in the mysql database that sets the maximum number of news posts to be posted to the website. The graphical construction of the news posts are controlled by the news.php template file that is included for each post.
My website is tied very tightly to my PHPBb2 forums. The members list in the navbar is pulled from the Clan Members usergroup on the forums, as is the information in their profiles. If you'd like to look at my website for a better idea of how things are setup, here it is: Apocalyptic Visions
I just started learning PHP in August and this website is my first real project. It's ran entirely on PHP and a MySQL database. Hope this helps you out, sorry about the messy code. I even had to look over the function for a few minutes to remember exactly how it worked lol
Last edited by Redline; 10-23-2004 at 06:08 PM.
|
|
|
10-27-2004, 02:32 PM
|
#25 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
Oh man that is cool *takes note*
Gives me so many ideas for my GTA: San Andreas site!
I'm thinking along the lines of this site's tutorial system.
I post a new topic into the forum in my admin section so only I can see it and it is pulled off a nav bar as a new page. The page's main body is pulled from the foprum's database message body etc etc ...
Basically recycling the phpbb forum to turn it into a CMS 
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
10-27-2004, 07:13 PM
|
#26 (permalink)
|
|
PHP Student
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 151
|
Yup that's exactly what I did with my site. It works great, the most recent news posts are on the front page, and the rest are archived in the forums 
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 03:48 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|