Solved

Problem with file

Posted on 2002-04-13
8
198 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
Comment Utility
Is there a problem just to include that file?

include($contentFile); or

require($contentFile);

Batalf
0
 
LVL 5

Expert Comment

by:andriv
Comment Utility
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
Comment Utility
Sorry Batalf, You submitted yours while I was still typing and did not know.
0
 

Author Comment

by:kplonk
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 32

Expert Comment

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

Author Comment

by:kplonk
Comment Utility
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
Comment Utility
Maybe you could use the buffer-functions:

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

Author Comment

by:kplonk
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 count occurrences of each item in an array.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now