Page 1 of 1

Procedure that imitates file_get_contents() for PHP4

Posted: Fri Sep 23, 2005 7:52 am
by pilau
Please consider this piece of code:

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}'>&nbsp;
	 <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=''>&nbsp;
	 <input type='text' name='".return_month_name($var)."[row".$n."][eventname]' size='50' value='Enter name here'></td>
        </tr>
	";
		}
	   }
    } //Master
 } // print function end
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

Posted: Fri Sep 23, 2005 8:05 am
by Chris Corbyn
file_get_contents() works in PHP4 too. I looked through that script you posted and I can't see any functions that are exclusive to PHP5 although there's a few undefined functions such as array_combine_emulated() which I assume are defined in another file somewhere?

Posted: Fri Sep 23, 2005 12:15 pm
by pilau
They aren't defined since it's not the entire file. The entire file is 175 lines long and the other parts weren't relevant so I didn't post them.

I checked php.net and it says there that file_put_contents() is only on PHP5. And it won't work on my hosting company's server which has PHP4 either.

Posted: Fri Sep 23, 2005 12:37 pm
by feyd
file_put_contents() is php5.. file_get_contents() has been around for a LONG time.

Posted: Fri Sep 23, 2005 1:06 pm
by pilau
Holy sh*t! 8O
I did mean file_put_contents!

Well, maybe now it would make things clearer...
Ok, nevermind this one. I'll be making a new post in the PHP Theory forum.

Bah, such a shame.