shadowayex Posted June 25, 2008 Share Posted June 25, 2008 I was wondering if there was a way I could print PHP Variables in the middle of HTML without opening PHP ( <?php ). For example, I have a variable that stores the username of a user and is used to greet the user on the pages. Is there a way I can have it written without typing it like this:Hello <?php echo $user ?>! Link to comment Share on other sites More sharing options...
Ingolme Posted June 25, 2008 Share Posted June 25, 2008 No, how else is the parser going to know that you're intending to write PHP?You can also write:<?phpecho "Hello {$user}!";?> Link to comment Share on other sites More sharing options...
shadowayex Posted June 25, 2008 Author Share Posted June 25, 2008 I figured as much. I just didn't want to open php over and over again for each variable on a page. Thanks anyways. Link to comment Share on other sites More sharing options...
Synook Posted June 26, 2008 Share Posted June 26, 2008 There is HEREDOC syntax if you want to write large strings with variables without having to worry about escaping. echo <<<EOTYour long string can go here.This is $foo['bar'] and {$foo->bar}.EOT; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.