Having a Problem...

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
Zero
Forum Newbie
Posts: 5
Joined: Sat Oct 11, 2003 6:31 pm
Location: United States

Having a Problem...

Post by Zero »

I'm currently building a new website, in PHP, and I'm building it differently than any others I've ever worked on. :) Well, I've run across a small problem, and I can't figure out the solution.

Error(s):
Parse error: parse error, unexpected $ in index.php on line 188
Fatal error: Call to a member function on a non-object in index.php on line 51
Fatal error: Call to a member function on a non-object in index.php on line 51

Code: Select all

<?php

error_reporting(E_ERROR|E_WARNING|E_PARSE);
set_magic_quotes_runtime(0);

$template = new template;

$gus      = new site;

$VARS = $gus->parse_incoming();

switch($VARS['act'])
{
	case 'news':
		load_archives();
		break;
		
	case 'games':
		load_coverage();
		break;
		
	case 'media':
		load_media();
		break;
		
	case 'interactive':
		load_interactive();
		break;
		
	case 'other':
		load_other();
		break;
		
	case 'affiliates':
		load_affiliates();
		break;
		
	case 'network':
		load_network();
		break;
		
	default:
		load_home();
		break;
}

function load_home() {
	
	$output = '';
	
	$output .= $template->page_head();
	
	$output = str_replace( "<% CSS %>", $template->css(), $output );
	
	echo $output;
	
}

class template {
	
	function page_head($title) {
		return <<<EOF
			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html>
			<head>
			<% CSS %>
			<title>Games Unlimited - $title</title>
			</head>
			<body>
			<a name='top'></a>
			<table width='700' align='center' cellpadding='0' cellspacing='0'>
			  <tr>
			    <td class='vspacer' colspan='3'>
			    </td>
			  </tr>
			  <tr>
			    <td colspan='3'>
			      <table width='700' border='1' cellpadding='0' cellspacing='0'>
			        <tr>
			          <td rowspan='3'>
			            <a href='http://www.guforums.net/home/'><img src='http://www.guforums.net/gamesunlimited.jpg' border='0' alt='' /></a>
			          </td>
			        </tr>
		EOF;
	}
	
	function css() {
		return <<<EOF
			<style type='text/css'>
			.website{width:700px;border-width:0px;font-family:tahoma;font-size:11px}
			.vspacer{height:20px}
			.hspacer{width:50px}
			.cspacer{width:10px}
			</style>
		EOF;
	}
	
}

class site {

	function parse_incoming()
    {
    	global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_CLIENT_IP, $REQUEST_METHOD, $REMOTE_ADDR, $HTTP_PROXY_USER, $HTTP_X_FORWARDED_FOR;
    	$return = array();
    	
		if( is_array($HTTP_GET_VARS) )
		{
			while( list($k, $v) = each($HTTP_GET_VARS) )
			{
				//$k = $this->clean_key($k);
				if( is_array($HTTP_GET_VARS[$k]) )
				{
					while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
					{
						$return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2);
					}
				}
				else
				{
					$return[$k] = $this->clean_value($v);
				}
			}
		}
				
		if( is_array($HTTP_POST_VARS) )
		{
			while( list($k, $v) = each($HTTP_POST_VARS) )
			{
				//$k = $this->clean_key($k);
				if ( is_array($HTTP_POST_VARS[$k]) )
				{
					while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
					{
						$return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2);
					}
				}
				else
				{
					$return[$k] = $this->clean_value($v);
				}
			}
		}
		
		return $return;
	}
    
    function clean_key($key) {
    
    	if ($key == "")
    	{
    		return "";
    	}
    	
    	$key = preg_replace( "/\.\./"           , ""  , $key );
    	$key = preg_replace( "/\_\_(.+?)\_\_/"  , ""  , $key );
    	$key = preg_replace( "/^([\w\.\-\_]+)$/", "$1", $key );
    	return $key;
    }
    
    function clean_value($val) {
    
    	if ($val == "")
    	{
    		return "";
    	}
    	
    	$val = preg_replace( "/&/"         , "&"         , $val );
    	$val = preg_replace( "/<!--/"      , "<&#33;--"  , $val );
    	$val = preg_replace( "/-->/"       , "-->"       , $val );
    	$val = preg_replace( "/<script/i"  , "<script"   , $val );
    	$val = preg_replace( "/>/"         , ">"          , $val );
    	$val = preg_replace( "/</"         , "<"          , $val );
    	$val = preg_replace( "/"/"        , """        , $val );
    	$val = preg_replace( "/\|/"        , "&#124;"        , $val );
    	$val = preg_replace( "/\n/"        , "<br>"          , $val ); 
    	$val = preg_replace( "/\\\$/"      , "&#036;"        , $val );
    	$val = preg_replace( "/\r/"        , ""              , $val ); 
    	$val = preg_replace( "/!/"         , "&#33;"         , $val );
    	$val = preg_replace( "/'/"         , "'"         , $val ); 
    	$val = stripslashes($val);                                     
    	$val = preg_replace( "/\\\/"       , "&#092;"        , $val ); 
    	return $val;
    }
   
}

?>
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

I, for one, am not going to count lines.
What are on lines 51 and 188?
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Parse error: parse error, unexpected $ in index.php on line 188

This means that some where within your code you are missing a ;

I've had a quick look but can't find where it's missing from..... this tedious job is going to have to be done you I'm afraid..... line by line!
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

STOP PRESS!!!

I think the problem is that your EOF; commands SHOULD NOT have any white space at the begining of them.

This won't work.........

Code: Select all

function css() { 
      return <<<EOF 
         <style type='text/css'> 
         .website{width:700px;border-width:0px;font-family:tahoma;font-size:11px} 
         .vspacer{height:20px} 
         .hspacer{width:50px} 
         .cspacer{width:10px} 
         </style> 
      EOF; 
   }

This should work.........

Code: Select all

function css() { 
      return <<<EOF 
         <style type='text/css'> 
         .website{width:700px;border-width:0px;font-family:tahoma;font-size:11px} 
         .vspacer{height:20px} 
         .hspacer{width:50px} 
         .cspacer{width:10px} 
         </style> 
EOF; 
   }
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

What's the difference between <<<EOF and <<<END anyway?
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Nothing. You can do <<<BLAH, shouldn't matter.

http://us2.php.net/echo
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Hmmmmm.... more PHP knowledge assimilated 8)
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Assimlate more. You can also do that with print.

http://us4.php.net/print
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

You can also define a variable for that matter.

Code: Select all

<?php
$var_with_lots_of_lines = <<< LINES
this
has
many
lines
LINES;
$var_with_lots_of_lines = nl2br($var_with_lots_of_lines);
echo $var_with_lots_of_lines;
?>
Get it? :D

-Nay
Zero
Forum Newbie
Posts: 5
Joined: Sat Oct 11, 2003 6:31 pm
Location: United States

Post by Zero »

Gen-ik, your solution worked for the parse error. Now, I've got:

Fatal error: Call to a member function on a non-object in index.php on line 51
Fatal error: Call to a member function on a non-object in index.php on line 53

Line 51/53, respectively:

Code: Select all

$output .= $template->page_head();
	
	$output = str_replace( "<% CSS %>", $template->css(), $output );
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

you need to create the actual instance of the class before line 51:

Code: Select all

<?php
$template = new template;

$output .= $template->page_head(); 
    
$output = str_replace( "<% CSS %>", $template->css(), $output );
?>
Post Reply