Jump to content

Help with a "Parse error: syntax error"


WatsonN

Recommended Posts

I'm writing a php page that will take the url variable and depending on the variable it will load diffrent pages. But i keep getting the error

Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' on line 8

And i'm not sure what needs to happen in the code to fix this.

<?php
$url = (isset($_GET['p']) ? $_GET['p'] : home);
?>

<?php
if ($url == $1) {
    include('$l1');
} elseif ($url == $2) {
    include('$l2');
} elseif ($url == $3) {
    include('$l3');
} else {
include('home');
}
?>

<?php
$1 = "foo1"
$2 = "foo2"
$3 = "foo3"
$home = "home.php"
$l1 = "bar1.php"
$l2 = "bar2.php"
$l3 = "bar3.php"
?>

So any help possible would be greatly appreciated  :)

 

Link to comment
https://forums.phpfreaks.com/topic/201828-help-with-a-parse-error-syntax-error/
Share on other sites

Thanks.

I changed all the variables that started with a number to something like s1, s2, s3. but now I'm getting an

Parse error: syntax error, unexpected T_VARIABLE on line 19

this is the new code

<?php
$url = (isset($_GET['p']) ? $_GET['p'] : home);
?>

<?php
if ($url == $s1) {
    include('$l1');
} elseif ($url == $s2) {
    include('$l2');
} elseif ($url == $s3) {
    include('$l3');
} else {
include('$home');
}
?>

<?php
$s1 = "foo1"
$s2 = "foo2" //Line 19
$s3 = "foo3"
$home = "home.php"
$l1 = "bar1"
$l2 = "bar2"
$l3 = "bar3"
?>

And i made sure the Var didn't start with a number and I'm no longer getting the "T_LNUMBER" error.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.