Hi,
Thanks for checking this out.
The error is that when I use ob_start to store the results of an include file my fwrite statement later on in the code works but only writes a blank file, whereas when the ob_start is not present the fwrite function writes the file with all the content present in it.
Anyone out there smarter than me about this stuff (not hard) please let me know how to solve this. Thanks.
<?php
//Storing the code to load into each div. Held in other php files to aid code resue
ob_start(); // start buffer
include ('../php_includes/sidebar_search_package.php');
$package = ob_get_contents(); // assign buffer contents to variable
ob_end_clean(); // end buffer and remove buffer contents
ob_start(); // start buffer
include ('../php_includes/sidebar_search_flight.php');
$flight = ob_get_contents(); // assign buffer contents to variable
ob_end_clean(); // end buffer and remove buffer contents
ob_start(); // start buffer
include ('../php_includes/sidebar_search_hotel.php');
$hotel = ob_get_contents(); // assign buffer contents to variable
ob_end_clean(); // end buffer and remove buffer contents
$filename = "../js_includes/SearchDiv.js";
$file = fopen($filename,"w");
if(!$file){
echo "Error creating searchDiv2";
exit;
}
if(!is_writable($filename)){
exit("$filename is not writable");
}
//Variable to hold content to be written to the javascript file. Double quotes are used for surrounding content and any quotes within the JS file should use single quotes or escaped double quotes
$to_write = "
function searchSwitch(DIV) {
switch (DIV)
{
case 'package':
package = '<p>Package loaded</p>';
document.getElementById('package').innerHTML = 'test';
document.getElementById('hotel').innerHTML = '';
document.getElementById('flight').innerHTML = '';
break;
case 'hotel':
hotel = '<p>Hotel loaded</p>';
document.getElementById('package').innerHTML = '';
document.getElementById('hotel').innerHTML = 'test';
document.getElementById('flight').innerHTML = '';
break;
case 'flight':
flight = '<p>Flight loaded</p>';
document.getElementById('package').innerHTML = '';
document.getElementById('hotel').innerHTML = '';
document.getElementById('flight').innerHTML = '<p>Flight Loaded</p>';
break;
default : alert('No search cat selected');
}
}//Closing function opening
";
$to_write = '<p>Test</p>';
$write = fwrite($file, $to_write);
if( !$write ){
echo "Content could not be written to the file $filename";
exit;
}
?>