Re: [PHP] Auto-generating HTML
On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote: Hey folks, Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance (assume this had some PHP in the middle, and there was actually a reason not to just put this in HTML in the first place): Unless you are looking at the HTML alot, you can just paste the source into an editor which can auto-format the code, or look at the code in firebug (that is the usual place where I look at my HTML.) If there is a specific place you want to look at in the html, just change the lines there to look like this: echo 'html '; but this will make your PHP quite messy if you do it alot. I would go with templating, as many here suggested. -- Simcha Younger simcha.youn...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On 20 Sep 2010, at 22:02, Bastien Koert wrote: The standard suggests that double quotes are to be used for HTML attributes. Where? -- Benjamin Hawkes-Lewis -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On 20 September 2010 19:56, Andy McKenzie amckenz...@gmail.com wrote: Hey folks, I have the feeling this is a stupid question, but I can't even find anything about it. Maybe I'm just not searching for the right things. Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance (assume this had some PHP in the middle, and there was actually a reason not to just put this in HTML in the first place): Simple PHP: ?php echo 'html'; echo 'head'; echo ' titlePage Title/title'; echo '/head'; echo 'body'; echo 'pThis is the page body/p'; echo '/body'; echo '/html'; ? Output page source: htmlhead titlePage Title/title/headbodypThis is the page body/p/body/html Now, I can go through and add a newline to the end of each line (echo 'html' . \n; and so on), but it adds a lot of typing. Is there a way to make this happen automatically? I thought about just building a simple function, but I run into problem with quotes -- either I can't use single quotes, or I can't use double quotes. Historically, I've dealt with the issue by just having ugly output code, but I'd like to stop doing that. How do other people deal with this? Thanks, Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php There is also the tidy extension which will take your badly formatted html tag soup and create formatted html, xhtml, etc. But really, why bother? Whenever I need to view the source I use the browsers viewsource option or firebug/console/etc. Essentially, client side. But using templates with heredoc ... ?php // Template to display a username row. // Requires a $a_User array return END_HTML tr th{$a_User['Name']}/th /tr END_HTML; sort of thing is easy enough to build. And in a loop ... $s_Users = ''; foreach($a_Users as $a_User) { $s_Users .= include '../templates/users.tmpl'; } Now, $s_Users contains the rows to display the users and you could do something to it if you wanted to. Of course, rolling your own system is fine, but there are other templating systems available, though, of course, PHP _IS_ the templating system, so why learn another one. If you are using a designer to structure the HTML and then adding your code to build the pages, then a templating system compatible with the designer's tools would be a good option. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On Tue, Sep 21, 2010 at 3:32 AM, Simcha Younger simcha.youn...@gmail.com wrote: On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote: Hey folks, Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance (assume this had some PHP in the middle, and there was actually a reason not to just put this in HTML in the first place): Unless you are looking at the HTML alot, you can just paste the source into an editor which can auto-format the code, or look at the code in firebug (that is the usual place where I look at my HTML.) If there is a specific place you want to look at in the html, just change the lines there to look like this: echo 'html '; but this will make your PHP quite messy if you do it alot. I would go with templating, as many here suggested. -- Simcha Younger simcha.youn...@gmail.com That's actually why this came up -- for the first time I AM looking at the generated HTML a lot. I'm building a frontend for a set of DBs we use (for various reasons none of the pre-built ones I could find would work for us), and I'm spending a fair amount of time trying to figure out whether I messed up the code, or the output just doesn't display as I expected. I've never done anything quite this complex, and have therefore never needed to look at the output html a lot. I've also just gotten tired of having my output completely unreadable... I'd like to have this project done right, and to me that means the source and the output should both be reasonably easy to parse, in addition to other things (paying a lot more attention to security than I usually do, for instance...). -Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Auto-generating HTML
From: Andy McKenzie I think the main thing I'm seeing is that there isn't a single, accepted, simple way to do this: no matter what I do, it will be a workaround of some type. Either I'm adding complexity (a function to convert everything), or I'm adding lines (heredoc/nowdoc seem to require that the opening and closing tags be on lines without any of the string on them), or I'm adding typing (adding ' . \n' to the end of every line of HTML). Perhaps I'll put some effort into building a function to do it, but not this week... I think for now I'll keep appending those newlines, and just have more code to fix at a later date. It's reasonably clean, it's just mildly annoying. It should be relatively easy to do a search and replace on the double tag locations and insert the newlines. Using tr(1) to replace all pairs with \n might be an improvement. Would it be easier to remove the extras, or to insert all of them in the first place? Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
At 2:56 PM -0400 9/20/10, Andy McKenzie wrote: Hey folks, I have the feeling this is a stupid question, but I can't even find anything about it. Maybe I'm just not searching for the right things. Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance -snip- You can mix html and php more effectively and with better clarity than that. Two things you should consider: 1. Effective use of includes. Please review and learn from this demo: http://sperling.com/examples/include-demo/ 2. Isolated use of echo()'s. I only mix html and php when it is necessary to inject values created by a php/mysql process. To show these values I typically use this format: ?php echo($whatever); ? within html -- for example: h1?php echo($title);?/h1 As such, all my code (html, css, php, mysql, javascript) is not complex, nor unreadable, and is easily maintainable. Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On Mon, 2010-09-20 at 14:56 -0400, Andy McKenzie wrote: Hey folks, I have the feeling this is a stupid question, but I can't even find anything about it. Maybe I'm just not searching for the right things. Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance (assume this had some PHP in the middle, and there was actually a reason not to just put this in HTML in the first place): Simple PHP: ?php echo 'html'; echo 'head'; echo ' titlePage Title/title'; echo '/head'; echo 'body'; echo 'pThis is the page body/p'; echo '/body'; echo '/html'; ? Output page source: htmlhead titlePage Title/title/headbodypThis is the page body/p/body/html Now, I can go through and add a newline to the end of each line (echo 'html' . \n; and so on), but it adds a lot of typing. Is there a way to make this happen automatically? I thought about just building a simple function, but I run into problem with quotes -- either I can't use single quotes, or I can't use double quotes. Historically, I've dealt with the issue by just having ugly output code, but I'd like to stop doing that. How do other people deal with this? Thanks, Alex Have you thought about SMARTY templates? easy to use, it's just a class, and you write your html in template files, which are easier to read than in your php files. Just a thought... i personally LOVE smarty template. Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On Mon, Sep 20, 2010 at 03:02:35PM -0400, TR Shaw wrote: On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote: Hey folks, I have the feeling this is a stupid question, but I can't even find anything about it. Maybe I'm just not searching for the right things. Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance (assume this had some PHP in the middle, and there was actually a reason not to just put this in HTML in the first place): Simple PHP: ?php echo 'html'; echo 'head'; echo ' titlePage Title/title'; echo '/head'; echo 'body'; echo 'pThis is the page body/p'; echo '/body'; echo '/html'; ? Output page source: htmlhead titlePage Title/title/headbodypThis is the page body/p/body/html Now, I can go through and add a newline to the end of each line (echo 'html' . \n; and so on), but it adds a lot of typing. Is there a way to make this happen automatically? I thought about just building a simple function, but I run into problem with quotes -- either I can't use single quotes, or I can't use double quotes. Historically, I've dealt with the issue by just having ugly output code, but I'd like to stop doing that. How do other people deal with this? Thanks, Alex Alex Just add a \n at the end as echo 'html\n'; That will not work. Single quotes means that the '\n' is not interpreted as a new line so you'll see a bunch of '\n' in the output. What I sometimes do is: $out = array(); $out[] = 'html'; $out[] = 'head'; $out[] = ' titlePage Title/title'; $out[] = '/head'; $out[] = 'body'; $out[] = 'pThis is the page body/p'; $out[] = '/body'; $out[] = '/html'; echo join(\n,$out); -- Act as if you were already happy and that will tend to make you happy. -- Dale Carnegie Rick Pasottor...@niof.nethttp://www.niof.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On Mon, Sep 20, 2010 at 3:47 PM, Steve Staples sstap...@mnsi.net wrote: On Mon, 2010-09-20 at 14:56 -0400, Andy McKenzie wrote: Hey folks, I have the feeling this is a stupid question, but I can't even find anything about it. Maybe I'm just not searching for the right things. Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance (assume this had some PHP in the middle, and there was actually a reason not to just put this in HTML in the first place): Simple PHP: ?php echo 'html'; echo 'head'; echo ' titlePage Title/title'; echo '/head'; echo 'body'; echo 'pThis is the page body/p'; echo '/body'; echo '/html'; ? Output page source: htmlhead titlePage Title/title/headbodypThis is the page body/p/body/html Now, I can go through and add a newline to the end of each line (echo 'html' . \n; and so on), but it adds a lot of typing. Is there a way to make this happen automatically? I thought about just building a simple function, but I run into problem with quotes -- either I can't use single quotes, or I can't use double quotes. Historically, I've dealt with the issue by just having ugly output code, but I'd like to stop doing that. How do other people deal with this? Thanks, Alex Have you thought about SMARTY templates? easy to use, it's just a class, and you write your html in template files, which are easier to read than in your php files. Just a thought... i personally LOVE smarty template. Steve I've never used it, but I may take a closer look. Overall I tend to find templates and pre-built frameworks frustrating, but it may be time to break down and learn to use them. -Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On Mon, Sep 20, 2010 at 3:50 PM, Rick Pasotto r...@niof.net wrote: On Mon, Sep 20, 2010 at 03:02:35PM -0400, TR Shaw wrote: On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote: Hey folks, I have the feeling this is a stupid question, but I can't even find anything about it. Maybe I'm just not searching for the right things. Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance (assume this had some PHP in the middle, and there was actually a reason not to just put this in HTML in the first place): Simple PHP: ?php echo 'html'; echo 'head'; echo ' titlePage Title/title'; echo '/head'; echo 'body'; echo 'pThis is the page body/p'; echo '/body'; echo '/html'; ? Output page source: htmlhead titlePage Title/title/headbodypThis is the page body/p/body/html Now, I can go through and add a newline to the end of each line (echo 'html' . \n; and so on), but it adds a lot of typing. Is there a way to make this happen automatically? I thought about just building a simple function, but I run into problem with quotes -- either I can't use single quotes, or I can't use double quotes. Historically, I've dealt with the issue by just having ugly output code, but I'd like to stop doing that. How do other people deal with this? Thanks, Alex Alex Just add a \n at the end as echo 'html\n'; That will not work. Single quotes means that the '\n' is not interpreted as a new line so you'll see a bunch of '\n' in the output. What I sometimes do is: $out = array(); $out[] = 'html'; $out[] = 'head'; $out[] = ' titlePage Title/title'; $out[] = '/head'; $out[] = 'body'; $out[] = 'pThis is the page body/p'; $out[] = '/body'; $out[] = '/html'; echo join(\n,$out); Interesting. I hadn't thought of that, but it could work. It'd still be quite a bit of extra typing, but at least I find it more readable... -Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On 20 September 2010 21:56, Andy McKenzie amckenz...@gmail.com wrote: On Mon, Sep 20, 2010 at 3:50 PM, Rick Pasotto r...@niof.net wrote: On Mon, Sep 20, 2010 at 03:02:35PM -0400, TR Shaw wrote: On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote: Hey folks, I have the feeling this is a stupid question, but I can't even find anything about it. Maybe I'm just not searching for the right things. Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance (assume this had some PHP in the middle, and there was actually a reason not to just put this in HTML in the first place): Simple PHP: ?php echo 'html'; echo 'head'; echo ' titlePage Title/title'; echo '/head'; echo 'body'; echo 'pThis is the page body/p'; echo '/body'; echo '/html'; ? Output page source: htmlhead titlePage Title/title/headbodypThis is the page body/p/body/html Now, I can go through and add a newline to the end of each line (echo 'html' . \n; and so on), but it adds a lot of typing. Is there a way to make this happen automatically? I thought about just building a simple function, but I run into problem with quotes -- either I can't use single quotes, or I can't use double quotes. Historically, I've dealt with the issue by just having ugly output code, but I'd like to stop doing that. How do other people deal with this? Thanks, Alex Alex Just add a \n at the end as echo 'html\n'; That will not work. Single quotes means that the '\n' is not interpreted as a new line so you'll see a bunch of '\n' in the output. What I sometimes do is: $out = array(); $out[] = 'html'; $out[] = 'head'; $out[] = ' titlePage Title/title'; $out[] = '/head'; $out[] = 'body'; $out[] = 'pThis is the page body/p'; $out[] = '/body'; $out[] = '/html'; echo join(\n,$out); Interesting. I hadn't thought of that, but it could work. It'd still be quite a bit of extra typing, but at least I find it more readable... Ash already mentioned it: heredoc format. Much easier, less typing, easier to read, keeps formatting, etc, etc etc. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On Mon, Sep 20, 2010 at 3:59 PM, Peter Lind peter.e.l...@gmail.com wrote: On 20 September 2010 21:56, Andy McKenzie amckenz...@gmail.com wrote: On Mon, Sep 20, 2010 at 3:50 PM, Rick Pasotto r...@niof.net wrote: On Mon, Sep 20, 2010 at 03:02:35PM -0400, TR Shaw wrote: On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote: Hey folks, I have the feeling this is a stupid question, but I can't even find anything about it. Maybe I'm just not searching for the right things. Here's the problem. I'm writing a lot of pages, and I hate going in and out of PHP. At the same time, I want my HTML to be legible. When you look at it, that's kind of a problem, though... for instance (assume this had some PHP in the middle, and there was actually a reason not to just put this in HTML in the first place): Simple PHP: ?php echo 'html'; echo 'head'; echo ' titlePage Title/title'; echo '/head'; echo 'body'; echo 'pThis is the page body/p'; echo '/body'; echo '/html'; ? Output page source: htmlhead titlePage Title/title/headbodypThis is the page body/p/body/html Now, I can go through and add a newline to the end of each line (echo 'html' . \n; and so on), but it adds a lot of typing. Is there a way to make this happen automatically? I thought about just building a simple function, but I run into problem with quotes -- either I can't use single quotes, or I can't use double quotes. Historically, I've dealt with the issue by just having ugly output code, but I'd like to stop doing that. How do other people deal with this? Thanks, Alex Alex Just add a \n at the end as echo 'html\n'; That will not work. Single quotes means that the '\n' is not interpreted as a new line so you'll see a bunch of '\n' in the output. What I sometimes do is: $out = array(); $out[] = 'html'; $out[] = 'head'; $out[] = ' titlePage Title/title'; $out[] = '/head'; $out[] = 'body'; $out[] = 'pThis is the page body/p'; $out[] = '/body'; $out[] = '/html'; echo join(\n,$out); Interesting. I hadn't thought of that, but it could work. It'd still be quite a bit of extra typing, but at least I find it more readable... Ash already mentioned it: heredoc format. Much easier, less typing, easier to read, keeps formatting, etc, etc etc. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype You may well be right; it's a format I haven't used much, but it may well be the right choice here. I think the main thing I'm seeing is that there isn't a single, accepted, simple way to do this: no matter what I do, it will be a workaround of some type. Either I'm adding complexity (a function to convert everything), or I'm adding lines (heredoc/nowdoc seem to require that the opening and closing tags be on lines without any of the string on them), or I'm adding typing (adding ' . \n' to the end of every line of HTML). Perhaps I'll put some effort into building a function to do it, but not this week... I think for now I'll keep appending those newlines, and just have more code to fix at a later date. It's reasonably clean, it's just mildly annoying. Thanks, all, and if anyone comes up with a really elegant solution, please let me know! -Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
Here's a related question maybe one of you can answer: is there any place in HTML (not PHP, but actually in HTML) where there's a difference between a single quote and a double quote? As nearly as I can tell, it shouldn't ever matter. If that's the case, using double-quotes to enclose an echo gets a lot simpler... -Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto-generating HTML
On Mon, Sep 20, 2010 at 4:52 PM, Andy McKenzie amckenz...@gmail.com wrote: Here's a related question maybe one of you can answer: is there any place in HTML (not PHP, but actually in HTML) where there's a difference between a single quote and a double quote? As nearly as I can tell, it shouldn't ever matter. If that's the case, using double-quotes to enclose an echo gets a lot simpler... -Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The standard suggests that double quotes are to be used for HTML attributes. It might be easier to use single quotes to wrap the whole set and therefore allow the user of double quotes in your output. My personal preference in what you are talking about is to have a view function that takes an array of data and perhaps errors and then shows the form with no other processing than maybe a loop. That way I can create the HTML as I please, copy and paste it into the function, and then do what ever I need to, to process the data before turning that into an array and passing it into the function function showForm($data, $errors){ ? Name: input type=text value=?php echo $data['name']; ? name=name ?php }//end function ? -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php