Example 1

	SDL_Init(SDL_INIT_VIDEO);
	$flags=SDL_HWSURFACE;
	$screen=SDL_SetVideoMode(640, 480, 32, $flags);
	
	function drawRect($s,$x,$y,$w,$h,$r,$g,$b,$a) {
		$f=$s["format"];
		$c=SDL_MapRGBA($f,$r,$g,$b,$a);
		$rect=array(
			"x"=>$x,"y"=>$y,"w"=>$w,"h"=>$h
		);
		SDL_FillRect($s,$rect,$c);                              
		SDL_UpdateRect($s,$x,$y,$w,$h);
	}
	drawRect($screen,100,100,50,50,255,0,0,0);
	while ($ended==0) {
		while (SDL_PollEvent(&$event)) {
			switch($event["type"]) {                                        
			case SDL_QUIT:
				echo "SDL_Quit received, quitting\n";
				$ended=1;
				break;
			case SDL_KEYDOWN:
				$keysym=$event["key"]["keysym"]["sym"];
				if ($keysym==SDLK_q) {
			        echo "Q pressed, quitting\n";
	    		    $ended=1;
				}
				break;
			}
		}
	}
	$ret=SDL_Quit();