pengu Posted July 6, 2009 Share Posted July 6, 2009 Hey guys, Question about the echo function. I'm putting some HTML within the variable. Having trouble with the javascript so the codes with the " " and I'm using ' ' for anything else, but then I run into the problem of javascript using ' ' within " " tags. The $message is used in an echo statement further down the page. Is there a way around this? <?php session_start(); if ($_SESSION['logged_in'] == false) { $message="<div class='login'><form id='login-form' method='post' action='login.php'><fieldset><h2>Login to Web Site</h2><p>Username: <input type='text' name='username' id='username' size='17' /></p><p>Password: <input type='password' name='password' id='password' size='17'/></p><input type='submit' name='submit' id='submit' value='Login' /></fieldset></form></div>" ; } else { $message="<div class='login'><div id='login-form'><fieldset><h2>Welcome " . $_SESSION['username'] . "</h2><p><a href='javascript:popUp(email.php)'>Email</a> <a href='logout.php'>Logout</a></p></fieldset></div></div>" ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/164893-solved-echo-function/ Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 Im not 100% sure i understand your question, but you can put " s inside of " " by escaping them... like echo "he said "yo" "; will break, but echo "he said \"yo\" "; will be fine. is that help? Quote Link to comment https://forums.phpfreaks.com/topic/164893-solved-echo-function/#findComment-869531 Share on other sites More sharing options...
pengu Posted July 6, 2009 Author Share Posted July 6, 2009 Umm this is where the problem is, I forgot to fix this up before. It only displays javascript:popUp( when you hover over it. <?php echo "<a href='javascript:popUp('email.php')'>Email</a>"; ?> edit: Just went over what you said, I will try it. Edit2: thank you so much seventheyejosh, it worked a treat. Quote Link to comment https://forums.phpfreaks.com/topic/164893-solved-echo-function/#findComment-869532 Share on other sites More sharing options...
.josh Posted July 6, 2009 Share Posted July 6, 2009 You can either escape the ones you are using to delimit the echo, example: echo '<a onclick = "someFunction(\'blah\')" ... '; or you can use HEREDOC echo TEXTBLOCK <a onclick = "someFunction('blah')" .... some 'blah' "blahblah" TEXTBLOCK; ?> Quote Link to comment https://forums.phpfreaks.com/topic/164893-solved-echo-function/#findComment-869534 Share on other sites More sharing options...
pengu Posted July 6, 2009 Author Share Posted July 6, 2009 thanks for your help guys echo "<a href=\"javascript:popUp('email.php')\">Email</a>" ; worked Quote Link to comment https://forums.phpfreaks.com/topic/164893-solved-echo-function/#findComment-869536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.