Solved

Problem with file

Posted on 2002-04-13
8
200 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php construct 5 28
ignore other .htaccess 2 45
000webhost.com default error log 1 28
How to check if a session is disconnected in php 9 13
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

832 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