Page 1 of 1

Need basic help using PHP.

Posted: Mon Dec 18, 2006 6:32 pm
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]

Posted: Mon Dec 18, 2006 6:37 pm
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....

Posted: Mon Dec 18, 2006 6:41 pm
by Zoxive

Code: Select all

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