Procedure that imitates file_get_contents() for PHP4
Posted: Fri Sep 23, 2005 7:52 am
Please consider this piece of code:
The call for these functions is: print_page(read_contents());
Since I just discovered that my hosting service (I made this on my local server) has only PHP4, I'd like somebody to guide me on how to make the reading function work on PHP4. (don't do it yourself, pleasem guide me - I want to learn.)
Cheers
Code: Select all
function read_contents() {
$events_script = file_put_contents("events.script");
$file = preg_split("/events\[[0-9]{1,2}\]=\{/", $events_script);
array_shift($file);
return $file;
} // read end
function print_page($months) {
//Begin Master array interpretation
while (list($var, $val) = each($months)) {
preg_match_all("#^\s*(\d+):\"(.*?)\".*$#m", $months[$var], $events);
array_shift($events);
print " <tr bgcolor=\"#FFCC00\">
<td colspan=\"2\">
<input type=\"checkbox\" onClick=\"getStatus('".return_month_name($var)."')\" checked>
" . return_month_name($var) . " <font size=\"1\">(Uncheck to remove events)</font>
</td>
</tr>
";
//Begin Secondary array interpretation
$events = array_combine_emulated($events[0],$events[1]);
$i = 0;
while (list($event_key, $event_val) = each($events)) {
$i++;
print " <tr>
<td bgcolor='#FF9900' width='10'>
<input type='checkbox' name='".return_month_name($var)."[row".$i."][checkbox]' value='".$event_key."' onClick=\"checkBox('".return_month_name($var)."',".$i.")\" checked>
<input type='hidden' name='".return_month_name($var)."[row".$i."][present]' value='true'>
</td>
<td bgcolor='#FFFFCC' width='530' colspan='2'>
<input type='text' name='".return_month_name($var)."[row".$i."][day]' size='1' value='{$event_key}'>
<input type='text' name='".return_month_name($var)."[row".$i."][eventname]' size='50' value='{$event_val}'>
</td>
</tr>
";
} //Secondary
if ($_POST['action'] == "addfields" && $_POST['monthadd'] == return_month_name($var))
{
for($j=1; $j <= $_POST['nof']; $j++)
{
$n = $i + $j;
print " <tr>
<td bgcolor='#FF9900' width='10'>
<input type='checkbox' name='".return_month_name($var)."[row".$n."][checkbox]' value='' onClick='' checked>
<input type='hidden' name='".return_month_name($var)."[row".$n."][present]' value='true'>
</td>
<td bgcolor='#FFFFCC' width='530' colspan='2'>
<input type='text' name='".return_month_name($var)."[row".$n."][day]' size='1' value=''>
<input type='text' name='".return_month_name($var)."[row".$n."][eventname]' size='50' value='Enter name here'></td>
</tr>
";
}
}
} //Master
} // print function endSince I just discovered that my hosting service (I made this on my local server) has only PHP4, I'd like somebody to guide me on how to make the reading function work on PHP4. (don't do it yourself, pleasem guide me - I want to learn.)
Cheers