OB Start Issues

As normal I start on live server building my code and then move over to EXEOut. What works on live server not always works with EXEOut and requires tweaks. Below has me confused, any input much appreciated.

// Start the buffering //
ob_end_clean();
ob_start();
include($storagelocation.‘example001/index.php’);

// Get the content that is in the buffer and put it in your file //
file_put_contents($storagelocation.‘example001/index.html’, ob_get_contents());
ob_end_clean();

The above code does create the index.html from index.php, but only the closing tags and .

Maybe it is not possible to use this in EXEOut? Or, maybe needs to use scripting?

Any input / examples much appreciated!

I just remembered that due to buffer restrictions the above will only work if in same folder as files working with.

Any one know of another way to execute the php files and then copy html source to a .html file?

What do you want to do exactly? Create a local html file?

Short story yes. Long story yes, but need to “execute” the php page and then create the html page.

Do this all the time at online site (private teachers membership) and also with few other software’s. Hoping to move away from the other software platforms and sure EXEOut.

Maybe you could use PHP’s eval function?

$mydata = eval('?>' . file_get_contents($storagelocation.'example001/index.php') . '<?php ');

// Get the content that is in the buffer and put it in your file //
file_put_contents($storagelocation.'example001/index.html', $mydata);

$mydata = eval('?>' . file_get_contents($storagelocation.'example001/index.php') . '<?php ');

// Get the content that is in the buffer and put it in your file //
file_put_contents($storagelocation.'example001/index.html', $mydata);

Got excited but sadly not working. The contents of index.php are not written and seem to be displayed on page.

As a test, created a file called php-to-html.php with above script. The index.html is created but with no content. But, the content of index.php is actually displayed on the php-to-html.php page. Weird.

Got it “sort of” working using different variation of your code:

$myfile = file_get_contents($storagelocation.'example001/index.php');
$content = eval("?>$myfile");
file_put_contents($storagelocation.'example001/index.html', $myfile);

But since index.php has combination of html/php, eval not working for me.

Going to have to find a way to use obstart…

This is driving me nuts (or nuttier).

Have now tried CURL and still cannot get working. Can use the below CURL on live server, XAMPP, PHP Desktop and works flawless (or course without defining/using $storagelocation):

$storagelocation = exo_getglobalvariable('HEPubStorageLocation', '');

$route = "$storagelocation";
$url = "$storagelocation.'example001/index.php'";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );

//html in $html
$html = curl_exec($ch);

//save html
$fh = fopen($storagelocation.'example001/index.html', 'w') or die("can't open file");
        fwrite($fh, $html);
        fclose($fh);

curl_close($ch);

echo $route . "" . $url;
echo $url;

CURL is writing the index.html to directory but is blank. Have tried so many combinations of $storagelocation my eyes have crossed:)

When I echo the paths, they look fine.

Anyone have any ideas?

curl can’t access internal URLs that begin with http://heserver or ghe://heserver. These URLs are internal schemes only recognized by the Chromium engine.
XAMPP and other similar products use a local web server that opens a port on localhost. That’s why curl can access the URLs (and any web browser). ExeOutput doesn’t.

What about outputting the Html code with simple echo? Or using a template engine?

Hummm. I am using CURL with sqlite databases that use the "data folder, did not know there would be difference. Thought if could read/write to Data folder, could write to users/public directory.

Ready to put this behind me and move on if cannot get working:)

@gdgsupport is this still a valid string for 2018 versions (used last in V2):

function GetAppDataPath: String;
begin
Result := GetSpecialFolderPath(28);
end;

In V2 I could get the users AppData like:

:\Users<user>\AppData\Local\

echo $path. "\\mathmachine\\test.txt";

Thanks!

Yes, GetSpecialFolderPath is still available in last ExeOutput.

Maybe you can point me further along to my destination:)

When I use $path. "\\mathmachine\\test.txt"; I am reading/writing to the custom storage folder using CURL. BUT, the contents are not going into the “Application GUID” folder.

Can you please give me the correct syntax / path to $path. "\\mathmachine\\<GUID>\\test.txt";

I am stuck at this point and either overlooking info in docs or it does not exist.

Thanks

Is it what you are looking for?

<?php $storagelocation = exo_getglobalvariable('HEPubStorageLocation', '');
echo $storagelocation;?>

I wish it was that simple. You can see have already tried that OB Start Issues - #8 by oldteacher and many different flavors:) (ie with ob_start, file_get, etc).

I appreciate the follow up much, but have moved on and used another software for that specific project.

Thanks again for your input.

Happy Holidays!

Since we will be releasing ExeOutput 2019 in some days, we came back to your problem and it looks like it is working as expected.

<?php

    // Start the buffering //
    ob_end_clean();
    ob_start();
	$storagelocation = exo_getglobalvariable('HEPubStorageLocation', '');
	
    include($storagelocation.'test/page.php');

    // Get the content that is in the buffer and put it in your file //
    file_put_contents($storagelocation.'test/page.html', ob_get_contents());
    ob_end_clean();

	echo 'DONE';

?>

In the storage folder, we created page.php in test subfolder with code:
<?php

echo 'DONE';

?>
Et bien sur le HTML en <b> gras </b>

Running the script in ExeOutput generates the page.html file in the same folder as the php version, and with the correct content:

DONEEt bien sur le HTML<b> gras </b>

One question: are you trying to make a console app or a GUI app with ExeOutput?

Thanks guys for trying to help me! This may come in handy in the future.

Making a GUI app.

One note totally forgot to mention: The PHP file I am attempting to execute contains XML, like:

$storagelocation = exo_getglobalvariable('HEPubStorageLocation', '');
$file = simplexml_load_file($storagelocation.'/math101/files/site_data.xml');
foreach($file->data as $row){
?>

<p><?php echo $row->question001; ?></p>

<?php
}
?>

The XML file is something like this:

<?xml version="1.0"?>
<site>
  <data>
    <id>0</id>
    <question001>What is 2 X 22?</question001>
  </data>
</site>

So the OBStart should create the HTML file. This works fine on every other platform tried, just not exeout.

Did not think to mention that earlier but it may have bearing on why not working. Cannot see why it would not work just because XML, but did not want to send you guys on wild chase.

Thanks again for helping.