Posted By

MMDeveloper on 02/24/09


Tagged

escape php html variable unescape


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

asterfr
umang_nine


Set variable to long string of unescaped HTML code


 / Published in: PHP
 

URL: http://www.mechanicmatt.com/toDo/

While working on a lite project management software I started using this one method of setting a variable's value to a long string of HTML (login form module for example). You can either go through the trouble of escape all the quotation characters and when you have to edit it, unescape it, make your changes, and re-escape it... or you can simply use this method.

  1. private function printLoginForm() {
  2. $form = <<<EOT
  3. <form method="post" action="index.php">
  4. <input type="hidden" name="component" value="login" />
  5. <input type="hidden" name="task" value="login" />
  6. Username:<br />
  7. <input name="login_username" type="text" id="login_username" size="15" />
  8. <br />
  9. Password:<br />
  10. <input name="login_password" type="password" id="login_password" size="15" />
  11. <br />
  12. <br />
  13. <div align="right">
  14. <input type="submit" name="login_submit" id="login_submit" value="Log-In" />
  15. </div>
  16. </form>
  17. EOT;
  18.  
  19. return $form;
  20. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: timme on August 21, 2009

I like the idea behind it, but I like to do it a bit differently. I pass a function containing html code as a variable, so I have something like

Title
<p>Content goes here</p>

And then I just pass the variable to a template function that uses it. What I like about that is that it pretty much lets me create an html page, that just has a little bit of extra stuff at the start and the end. As an added bonus, the text editor I use, notepad++ know to format the html as html and the php as php, so

Posted By: timme on August 21, 2009

I like the idea behind it, but I like to do it a bit differently. I pass a function containing html code as a variable, so I have something like

Title
<p>Content goes here</p>

And then I just pass the variable to a template function that uses it. What I like about that is that it pretty much lets me create an html page, that just has a little bit of extra stuff at the start and the end. As an added bonus, the text editor I use, notepad++ know to format the html as html and the php as php, so

Posted By: timme on August 21, 2009

I like the idea behind it, but I like to do it a bit differently. I pass a function containing html code as a variable, so I have something like

Title
<p>Content goes here</p>

And then I just pass the variable to a template function that uses it. What I like about that is that it pretty much lets me create an html page, that just has a little bit of extra stuff at the start and the end. As an added bonus, the text editor I use, notepad++ know to format the html as html and the php as php, so

Posted By: timme on August 21, 2009

Oh jeeze this comment system is retarded. It isn't making up my php code correctly, and reloading the page resent it twice. Sorry.

Posted By: MMDeveloper on August 25, 2009

yeah the commenting portion leaves much to be desired sometimes. I am interested in the method you use, always interested in alternative logic. If you want, can you mail me your example? guru at mechanicmatt dot com

Posted By: asterfr on January 11, 2011

You can't use this one for an attribute declaration, you have to set in inside a function

You need to login to post a comment.