Re: New to PHP question

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

 



On Wed, Jan 28, 2009 at 2:58 PM, Don Collier <dcollier@xxxxxxxxxxxxxxx>wrote:

>
>
> Paul M Foster wrote:
>
>> On Wed, Jan 28, 2009 at 12:05:34PM -0700, Don Collier wrote:
>>
>>
>>
>>> I am just learning PHP from the O'Reilly "Learning PHP 5" book and I
>>> have a question regarding the formatting of text.  Actually it is a
>>> couple of questions.
>>>
>>> First, when I use the \n and run the script from the command line it
>>> works great.  When I run the same code in a browser it does not put the
>>> newline in and the text runs together.  I know that I can use <br/> to
>>> do the same thing, but why is it this way?
>>>
>>>
>>
>> Browser don't break lines on the \n character. They only break on <br>
>> or <p> tags. That's just the way it is. You can use the PHP function
>> nl2br() to insert <br> tags where the \n characters are.
>>
>>
>>
>>> The second question is closely related to the first.  When formatting
>>> text using printf the padding works great when running from the command
>>> line but not at all when in a browser.
>>>
>>>
>>
>> Browsers don't respect multiple spaces, etc., except in between certain
>> tags, like <pre></pre>. Instead, they combine multiple spaces into a
>> single space and break lines where they like, based on layout. You can
>> use the HTML &nbsp; character if you don't want lines or phrases to
>> break at the whim of the browser. If you want exact layout (columns
>> lined up, etc.), the simplest solution is to use HTML tables.
>>
>> Paul
>>
>>
>>
> Thanks to everyone that responded.
> From what I am seeing in the responses if I plan on using php for command
> line scripts things get written one way.  If, on the other hand, the php is
> written for a web page it gets written a slightly different way inserting
> html where necessary for formatting.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Not quite true in a properly layered application. Separating the data from
the display (whatever that is) is prime idea behind the MVC (Model View
Controller) design pattern. This way your code that runs via the CLI
(command line) can produce the same data as the code that gets the data for
the HTML. The only difference is what you plan to do with that data. You
could feed it to a controller and let the controller feed it to a View to
render in a browser, or send it to a FileOutput class to create a file of
the data for comsumption by another resource.


-- 

Bastien

Cat, the other other white meat

[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