[PHP] New to PHP question
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 to do the same thing, but why is it this way? 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. Here is the code that I am working with: Thanks for the help everyone. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] New to PHP question
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 to do the same thing, but why is it this way? Browser don't break lines on the \n character. They only break on or tags. That's just the way it is. You can use the PHP function nl2br() to insert 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 . Instead, they combine multiple spaces into a single space and break lines where they like, based on layout. You can use the HTML 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
Re: [PHP] New to PHP question
Paul M Foster wrote: See? This is what I'm talking about. *I* understand what you're saying, Don, and I agree. But this guy is just learning PHP from what is arguably not one of the best books on PHP (IMO). And you're throwing MVC at him. Let him master the subtleties of the language first, then we'll give him the MVC speech. Yes, I know, they should learn proper programming practices from the beginning, blah blah blah. But think back to the first programming language you ever learned, when you were first learning it. If someone had thrown stuff like this at you, would you have had a clue? I had enough trouble just learning the proper syntax and library routines for Dartmouth BASIC and Pascal, without having to deal with a lot of "metaprogramming" stuff. This is the problem when you get newbies asking questions on a list whose membership includes hardcore gurus. The gurus look at things in such a lofty way that answering simple questions at the level of a beginner sounds like a dissertation on the subtleties of Spanish art in the 1500s. Just my opinion. Paul On that note, what would be a better book to learn from? I have always been a fan of the O'Reilly books, but I am open to differing flavors of kool-aid. One can never have too many resources. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] New to PHP question
Paul M Foster wrote: On Wed, Jan 28, 2009 at 01:45:07PM -0700, Don Collier wrote: On that note, what would be a better book to learn from? I have always been a fan of the O'Reilly books, but I am open to differing flavors of kool-aid. One can never have too many resources. The book that sits on my desk and is incredibly dog-eared is _Programming PHP_, also from O'Reilly. The whole back section is a reference on all the PHP functions and some extensions. The front part of the book explains nearly everything about the language. There are some errata in the book, which I've pointed out to O'Reilly, and when in doubt I check the function documentation on the php.net site. Paul I have this "Learning PHP 5" and at the same time bought "PHP and MySQL" also from O'Reilly. Ever since my first "Sed and Awk" book from them about 10 or so years ago I have been hooked. I do have others in my library but I usually give them a shot first to see if I get what I need. I will have to pick up a copy of the "Programming PHP" and give it a look. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Happy 1234567890 day!
Lists wrote: :-) Donovan Is there going to be someone contacting me about my prize? :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php