Need basic help using PHP.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xgm541
Forum Newbie
Posts: 1
Joined: Mon Dec 18, 2006 6:25 pm

Need basic help using PHP.

Post by xgm541 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am fairly new to PHP. I am taking a Java course, and alot of PHP seems similar to Java.

I would like to make a include command which includes the name of the file at the end of the page, for example

if the user goes to index.php?goto=downloads.php 

it calls for downloads.php.

So far i have this much:

Code: Select all

<?php
$path_parts = pathinfo('/www/htdocs/index.txt');

echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
?> 
			<?php include($path_parts['basename'])?>
it calls for index.txt, but it will only call for that specific file, i dont know how to make it detect whats in the browser.

I'm guessing you'd have to put in the parenthesis of the pathinfo the function, but im not sure how to do that. Any help is greatly appreciated.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

Heres an example of what you could do...

Page names would be aboutUs.php and contactUs.php in the following example
Here is the statment telling whatever you want to tell what the current page is ....

Code: Select all

<?

	if(empty($page))
{
	$page = $_REQUEST['page'];
	switch ($page) 
{
	case 'aboutUs':
		$title = 'About Us';
		break;
	case 'contactUs':
		$title = 'Contact Us';
		break;
	default:
		$page = 'aboutUs';
	    $title = 'About Us';
		break;
}
}


?>

Code: Select all

<title><? echo $title; ?></title>

And here is the include function...

Code: Select all

<? 
include($page.".php"); 
?>
Basically what this code will do is, if no page is selected (ie, when u first go to the site) page will be defined as aboutUs, which you can edit to perhaps home....
Last edited by iknownothing on Mon Dec 18, 2006 6:42 pm, edited 1 time in total.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Code: Select all

if(isset($_GET['goto'])){
     print $_GET['goto'];
}
Post Reply