Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

A PHP script that generates another

Links for php scripts

Moderators: macek, egami, gesf

A PHP script that generates another

Postby lucasearl » Fri May 02, 2014 10:43 am

Hey.

I'm trying to use a PHP script to generate another php script copying from a "stub" that has replacement tags. The problem I'm facing is opening a "stub" php script and reading it line by line. I've tried multiple functions: file_get_contents(), print_r(file($file)), where $file = fopen(filename). fgets, etc. echo file_get_contents() spits out the file only starting at a certain point, so I have wondered if it is trying to run the php that is in there. The odd thing, is that if I create a new file with exactly the same content, it won't display anything!

Currently I have:
Code: Select all
<?php
    if( file_exists("Stubs/test.txt")){
    echo "This works!";
    echo file_get_contents('Stubs/test.txt');
}
else{
    echo "This doesn't work!";
}
?>


and the txt file:

Code: Select all
<?php

require_once('util/import/ListHubImport.php');

class CBGoldKeyRealtyIncUTImport extends ListHubImport
{

    public function __construct($date = null, $printMessages = true)
    {
        parent::__construct(CO_ImportScript::CBGOLDKEYREALTYINCUT, $printMessages, null, 'Coldwell Banker Gold Key Reality Inc.');

        // CONNECTION INFO
        $dataConn = new DataConnection();
        $dataConn->setConnectionType(DataConnection::HTTP);
        $dataConn->setValidOfficeIds(array('38575'));

        $this->connectionInfo = $dataConn;

        $this->setSaveFilename($dataConn->getSaveDataPath() . "CBGoldKeyRealtyInc-UT_::DATE::.xml");

        $this->date = $date;
        $this->setSaveRecords(true);
        $this->fields = $this->skippedListings = array();
//...

    }

}

?>




This behavior is bizarre to me, and I'm running out of debugging options with php. Any help would be appreciated! Thanks. -Luc

PS. It shows everything from the line: $dataConn = new DataConnection(); to the end of the file.
lucasearl
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri May 02, 2014 10:30 am

Re: A PHP script that generates another

Postby peterachutha » Sun Jun 01, 2014 12:25 am

I suspect I may know why it did not appear to work. It is actually working but its not visible as it looks like the browser is chomping everything. Try changing your code so that the browser ignores it as text by placing the output in a textarea:-

<html>
<bod>
<?php
if( file_exists("test.txt")){
echo "This works!";
$mydata = file_get_contents('test.txt');
?>
<textarea rows="10" cols="80"><?php echo $mydata?></textarea>
<?php
}
else{
echo "This doesn't work!";
}
?>
</body>
peterachutha
New php-forum User
New php-forum User
 
Posts: 10
Joined: Sat May 31, 2014 10:35 pm


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.