Procedure that imitates file_get_contents() for PHP4

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Procedure that imitates file_get_contents() for PHP4

Post 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
Last edited by pilau on Fri Sep 23, 2005 1:06 pm, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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?
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post 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.
Last edited by pilau on Fri Sep 23, 2005 1:07 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

file_put_contents() is php5.. file_get_contents() has been around for a LONG time.
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post 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.
Post Reply