...

View Full Version : could some one help me with my switch page ??



mjs
01-23-2010, 12:04 PM
I am wondering if anyone out there can help with my switch page Please?


<html>
<body>

<?php include("templates/header.php"); ?>
<!-- link Menu -->
<a href="/default.php">Home</a>
<a href="faq/tutorials.php">Tutorials</a>
<a href="/references.php">References</a>
<a href="misc/examples.php">Examples</a>
<a href="misc/about.php">About Us</a>
<a href="/contact.php">Contact Us</a>
<!-- end link menu -->

<h1>Welcome to my home page!</h1>

<?php include("functions/body.php"); ?>

<?php include("templates/footer.php"); ?>
</body>
</html>

now, how to call link menu e.g (default.php, tutorials.php, etc) by dinamic change the body.php?

i tyr use switch page i.e.


<?
$page = $_GET['page'];
if (empty($page)) { $page = $_POST['page']; }
if (empty($page)) { $page = "body"; }

switch ($page) {

default:
$pagea[] = include("functions/body.php");
break;

case "orderform":
$pagea = include("/references.php");
break;

case "orderform":
$pagea = include("misc/about.php");
break;
}
?>

but it's seem doesn't work...
for any idea would be welcome and many thanks

abduraooft
01-23-2010, 12:23 PM
Are you trying to make something similar to the one explained at http://www.codingforums.com/showthread.php?t=174248

JAY6390
01-23-2010, 02:30 PM
You can't assign page contents from an include to a variable. You need to do it with something like file_get_contents

kbluhm
01-23-2010, 03:00 PM
You can't assign page contents from an include to a variable. You need to do it with something like file_get_contents

Yes you can.

file1.php


<?php

// do some processing up here

return 'John';

// everything below the return will not get
// processed for this particular file


file2.php


$name = include 'file1.php';

echo $name; // John


Though we are not sure the OP is doing this.

JAY6390
01-23-2010, 03:07 PM
lol returning a value isn't quite the same as getting an entire files content, but I know what you mean. I'd find it pretty pointless returning a value for each switch when the code could be put in the switches themselves

mjs
01-23-2010, 03:18 PM
Hi... I very thank for joining my question... bless and peace upon you all..

abduraooft
i'm not sure whether your link that what i need, but it seem different in my mind and also nothing clear there so i absolutely don't understand what the end.

JAY6390
file_get_contents ?? i ever heard it, but i blind, i just need more samples about file_get_contents with hopefully solve my case...

kbluhm
you put short code and with surely can solve my problem... but definitely i don't know how to start from your suggestion... would you make it more clear to me?

JAY6390
01-23-2010, 03:23 PM
if you need examples the manual is a great place to start
http://www.php.net/file_get_contents

mjs
01-23-2010, 04:16 PM
if you need examples the manual is a great place to start
http://www.php.net/file_get_contents
Nice guidance, i appreciate all your attentions..

n now i put what i catch from there:


<?php
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
?>


<html>
<body>

<?php include("templates/header.php"); ?>
<!-- link Menu -->
<a href="/default.php">Home</a>
<a href="faq/tutorials.php">Tutorials</a>
<a href="/references.php">References</a>
<a href="misc/examples.php">Examples</a>
<a href="misc/about.php">About Us</a>
<a href="/contact.php">Contact Us</a>
<!-- end link menu -->

<h1>Welcome to my home page!</h1>


<?php
$file = file_get_contents('faq/tutorials.php', FILE_USE_INCLUDE_PATH);
$file = file_get_contents('references.php', FILE_USE_INCLUDE_PATH);
$file = file_get_contents('misc/examples.php', FILE_USE_INCLUDE_PATH);
?>


<?php include("templates/footer.php"); ?>
</body>
</html>
it seem doesn't work, may i failed understand? help..;)

JAY6390
01-23-2010, 04:17 PM
You need to echo the $file

kbluhm
01-23-2010, 04:27 PM
If you use file_get_contents() on a local PHP file, any PHP code in the file will not be processed; it will be returned as plain text.

You need to include the file you wish to display.

If you want to capture the output of a file to be assigned to a variable:


ob_start();
include './body.php';
$source = ob_get_clean();

// $source now contains the parsed output of `./body.php`

echo $source;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum