Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.