From: "=?utf-8?B?YXNoQGFzaGxleXNoZXJpZGFuLmNvLnVr?=" on
He just said that's what he didn't want to do!

Thanks,
Ash
http://www.ashleysheridan.co.uk

----- Reply message -----
From: "TR Shaw" <tshaw(a)oitc.com>
Date: Mon, Sep 20, 2010 20:02
Subject: [PHP] Auto-generating HTML
To: "Andy McKenzie" <amckenzie4(a)gmail.com>
Cc: "PHP General list" <php-general(a)lists.php.net>



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';

Of course if your on windows you might want to output \r\n

Tom

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

From: Steve Staples on
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 ' <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
>


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

From: Rick Pasotto on
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);

--
"Act as if you were already happy and that will tend to make you happy."
-- Dale Carnegie
Rick Pasotto rick(a)niof.net http://www.niof.net
From: Andy McKenzie on
On Mon, Sep 20, 2010 at 3:47 PM, Steve Staples <sstaples(a)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 '  <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
>>
>
>
> 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
From: Andy McKenzie on
On Mon, Sep 20, 2010 at 3:50 PM, Rick Pasotto <rick(a)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 '  <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...

-Alex
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5
Prev: PHP Email Question
Next: not able to connect to MySQL