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
phpnoobyyy
Forum Newbie
Posts: 14 Joined: Mon Oct 12, 2009 3:27 pm
Post
by phpnoobyyy » Mon Oct 12, 2009 3:36 pm
Hi guys
As my name suggests, i'm new to php so please go easy on me.
I'm trying to output (unsuccessfully thus far) the following inside an echo:
Code: Select all
echo '
<li><a href="prices.php" class="topnav1">Prices</a></li>
<li><a href="order.php" class="prinav">Place an order</a></li>
<li class="linav"><?php if ( (isset($_SESSION[\'user_id\'])) && (!strpos($_SERVER[\'PHP_SELF\'], \'sign_out.php\')) ) {
echo \'<a href="sign_out.php">Sign out</a>\';}
else {
echo \'<a href="sign_in.php">Sign in</a>\';
}
?></li>';
Here's the same php code outside the
Code: Select all
bubble:
echo '
<li><a href="prices.php" class="topnav1">Prices</a></li>
<li><a href="order.php" class="prinav">Place an order</a></li>
<li class="linav"><?php if ( (isset($_SESSION[\'user_id\'])) && (!strpos($_SERVER[\'PHP_SELF\'], \'sign_out.php\')) ) {
echo \'<a href="sign_out.php">Sign out</a>\';}
else {
echo \'<a href="sign_in.php">Sign in</a>\';
}
?></li>';
I've googled for solutions but nothing seems to work. Help greatly appreciated....thanks
PHPnoobyyy
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Mon Oct 12, 2009 4:02 pm
An echo statement must be in <?php ?> tags. You can't have <?php ?> tags inside of <?php ?> tags.
Code: Select all
echo '<li><a href="prices.php" class="topnav1">Prices</a></li>'
. '<li><a href="order.php" class="prinav">Place an order</a></li>'
. '<li class="linav">';
if ( (isset($_SESSION['user_id'])) && (!strpos($_SERVER['PHP_SELF'], 'sign_out.php')) ) {
echo '<a href="sign_out.php">Sign out</a>';
} else {
echo '<a href="sign_in.php">Sign in</a>';
}
echo '</li>';
Last edited by
superdezign on Mon Oct 12, 2009 4:03 pm, edited 1 time in total.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Oct 12, 2009 4:02 pm
You cannot embed php inside a string, you will either need to break out of php or build the string sequentially.
Code: Select all
$output = '
<li><a href="prices.php" class="topnav1">Prices</a></li>
<li><a href="order.php" class="prinav">Place an order</a></li>
<li class="linav">
';
if ( (isset($_SESSION['user_id'])) && (!strpos($_SERVER['PHP_SELF'], 'sign_out.php')) ) {
$output .= '<a href="sign_out.php">Sign out</a>';}
else {
$output .= '<a href="sign_in.php">Sign in</a>';
}
$output .= '</li>';
echo $output;
Last edited by
John Cartwright on Mon Oct 12, 2009 4:03 pm, edited 1 time in total.
Reason: Too late :(
phpnoobyyy
Forum Newbie
Posts: 14 Joined: Mon Oct 12, 2009 3:27 pm
Post
by phpnoobyyy » Mon Oct 12, 2009 4:17 pm
That's great, it works.
Thanks a lot, really appreciated.