Spencer Posted January 25, 2013 Posted January 25, 2013 Hey there! I want to style an "echo" in PHP. ( You know. Make it blue, position it, ect. ) All the examples and places I have learned about this work, but this echo has a variable in it: echo '<div id="welcome_username">"Welcome, " . $myusername . "!"</div>'; The variable is $myusername ( Making it say "Welcome, Username!" =P ) Is there a different way to style an echo, when it has a variable? Thanks for your time. ~ Spencer ( If you must, here is the whole code... I do't think it is needed though. )++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ <?php session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } $myusername = $_SESSION['myusername']; ?> <html> <head> <title>Mbox:homepage</title> <script> window.setInterval(function(){ window.scrollTo(40, 220); }, 50); </script> <style> /*3DS SCREEN START*/ div#topscreen { position: absolute; top: 0px; left: 0px; height: 218px; width: 320px; background-color:#E0FFFF; z-index:2; } div#bottomscreen { position: absolute; top: 218px; left: 0px; height: 212px; width: 320px; background-color:#E0FFFF; } /*3DS SCREEN STOP*/ /* WELCOME USERNAME STYLE START */ div#welcome_username { color:#0000EE; font-weight: bold; position:absolute; top:5px; left:50px; } /* WELCOME USERNAME STYLE STOP */ </style> <meta name="viewport" content="width=320"> </head> <body> <!-- TOP SCREEN --> <div id="topscreen"> <?php echo '<div id="welcome_username">Welcome, . $myusername . !</div>'; ?> <p style="color:red; text-decoration:underline;">Homepage under construction.</p> </div id="topscreen"> <!-- BOTTOM SCREEN --> <div id="bottomscreen"> </div id="bottomscreen>" </body> </html>
Shinryuu Posted January 25, 2013 Posted January 25, 2013 2:49:40 PM - Shinryuu_: Mega_: '' don't process variables2:49:47 PM - Shinryuu_: only ""2:53:00 PM - Shinryuu_: one way to do it is to break out of the parser first, ?><div id="welcome_user"><?php echo "Welcome, $username"; ?></div> <?php2:53:38 PM - Shinryuu_: Mega_: otherwise you have to hack the crap out of it with the concat operator . For future reference. 1
ethanh Posted January 31, 2013 Posted January 31, 2013 You are using your quotes incorrectly. When referencing a variable you can either do it straight from the string using double quotes or put a string and variable together using a '.' Here is an example for how to add variables to a string: $name = 'Bob'; //Following outputs: My name is Bob echo "My name is $name"; //Following outputs: My name is $name echo 'My name is $name'; //Following outputs: My name is Bob echo 'My name is '.$name; For what you are doing you need to change some quotes. Either one of these should work for you. $myusername = 'Bob'; //Outputs: "Welcome, Bob!" echo '<div id="welcome_username">"Welcome, ' . $myusername . '!"</div>'; //Outputs: Welcome, Bob! echo '<div id="welcome_username">Welcome, ' . $myusername . '!</div>';
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now