Solved

Problem with file

Posted on 2002-04-13
8
202 Views
Last Modified: 2008-03-06
I have the following code that opens a file, the file is a php script file.

$contentFile="./" . $name . "/" . $filename;
$page_content=join("",file($contentFile));

name is a string that holds the taget dir name
fielname is a string that holds the name of the file to open and use.

the file in the test situation is called tes1.php and the contents of the file are as follows:

the test is comming
<?php

    echo "hello just testing";

?>

the test has run

$page_content is then echoed out to the screen at a later time. The problem i have is that the servere is not parsing the content of the php file that is being loaded, how do i do this thanks.
0
Comment
Question by:kplonk
  • 3
  • 3
  • 2
8 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 50 total points
ID: 6939140
Is there a problem just to include that file?

include($contentFile); or

require($contentFile);

Batalf
0
 
LVL 5

Expert Comment

by:andriv
ID: 6939146
I don't know exactly what you are attempting but if you want to execute the script within another you don't want to read the file, you must include the file.  When you use the file() function you are reading line by line, it is not executed. Try:

$contentFile="./" . $name . "/" . $filename;
include("$contentfile);

If this is not what you are trying to do, please explain.
0
 
LVL 5

Expert Comment

by:andriv
ID: 6939147
Sorry Batalf, You submitted yours while I was still typing and did not know.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kplonk
ID: 6939301
The problem with include is that the output of the include will be placed ad hock, what I need to do is buffer the output of the include statment into the var $page_content, that way i display it where and when i need to. Can this be done??
0
 
LVL 32

Expert Comment

by:Batalf
ID: 6939313
But can't you put the include() statement wherever you want and whenever you need too?
0
 

Author Comment

by:kplonk
ID: 6939331
no, the put put of the php script swops the content of $page_content with a label in a sort of html template and then outputs that, also so there is more than one type of file that can form the conten, php is just one of many, to move the include to the corret place would mean chopping all over the place and that will be messy.

Example 11-7 in php man seems to say that

return.php
<?php

$var = 'PHP';

return $var;

?>

noreturn.php
<?php

$var = 'PHP';

?>

testreturns.php
<?php

$foo = include 'return.php';

echo $foo; // prints 'PHP'

$bar = include 'noreturn.php';

echo $bar; // prints 1

?>


$page_content = include $contentFile; should work, but it still writes the content of the file out and not store it in the var, hmm what is going on here??
0
 
LVL 32

Expert Comment

by:Batalf
ID: 6939343
Maybe you could use the buffer-functions:

ob_start();
include("return.php");
$content = ob_get_contents();
ob_end_clean();
0
 

Author Comment

by:kplonk
ID: 6939353
Ok sorry peps sorted it, in the main code i used this code

                    $contentFile="./" . $name . "/" . $filename;
                    $page_content = include $contentFile;
                    $page_content = $page_content . addjumps();
                    return $page_content;

thanks for the include helop and also to you andriv a similer probelm you helped me with earler.

The trick is that the included script has to have a return statment and not a standard buffer out then all is well, in my example the included file has the line

return "at last i see the light!!"; and all is well.

thanks so much kieran
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question