Re: Auto-generating HTML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 20 September 2010 21:56, Andy McKenzie <amckenzie4@xxxxxxxxx> wrote:
> On Mon, Sep 20, 2010 at 3:50 PM, Rick Pasotto <rick@xxxxxxxx> 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 ' Â<title>Page Title</title>';
>>> > echo '</head>';
>>> > echo '<body>';
>>> > echo '<p>This is the page body</p>';
>>> > echo '</body>';
>>> > echo '</html>';
>>> >
>>> > ?>
>>> >
>>> >
>>> > Output page source:
>>> > <html><head> Â<title>Page Title</title></head><body><p>This 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[] = ' Â<title>Page Title</title>';
>> $out[] = '</head>';
>> $out[] = '<body>';
>> $out[] = '<p>This 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




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux