Tidying Up via PHP

Album Cover: Begin To Hope

"On the radio, you hear November Rain. That solo's awful long, but it's a good refrain."
Regina Spektor / On The Radio

Posted on March 25, 2004 6:04 PM in Web Development
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

After writing about some cool up-and-coming features of PHP 5 involving Tidy yesterday, I got to thinking about the way I typically code my PHP pages. I am guessing I use the same technique as a lot of people, interspersing PHP code in my XHTML, like so:

<p>
 <b>User Comments:</b>
</p>
<p>
 <? print(nl2br($comments)); ?>
</p>

As any experienced PHP programmer knows, as the interspersed PHP code gets more complex (e.g. utilizing while and for loops and dynamic content) it becomes increasingly more difficult to ensure that the XHTML it generates will look pretty (i.e. well structured).

By using the tidy_parse_string() function, you can replace all of your print() calls with string concatenation calls (e.g. $output .= nl2br($comments);) and hold off on outputting any actual XHTML source until you are all done processing via PHP.

When you do this, you save the structuring of your XHTML until the very last step, when your $output variable contains all the data to be output to the browser. Then, when it comes time to print the output, you do something like the following (which is explained a bit on Zend's site):

<?
 $options = array(
  "indent" => true,
  "indent-spaces" => 1,
  "wrap" => 72
 );
 $output = tidy_parse_string($output, $options);
 print($output);
?>

Doing so will, hypothetically speaking, since I haven't had a chance to try this out yet, tidy up all of your XHTML so it looks just as pretty as if you had hand-coded it yourself and didn't require any dynamic processing from PHP.

Pretty nifty, huh?

Comments

blog comments services on September 09, 2016 at 5:43 AM:

I havent any word to value this post.....Really i am inspired from this post....the individual who make this post it was an extraordinary human..thanks for imparted this to us.

Permalink

دكتور اسنان on September 20, 2016 at 10:22 AM:

I definitely really liked every part of it and i also have you saved to fav to look at new information in your site.

Permalink

Goodness, this is truly intriguing perusing. I am happy I discovered this and got the opportunity to peruse it. Incredible employment on this substance. I like it.

Permalink

http://twitter.com/iherb___coupon on September 26, 2016 at 5:33 AM:

I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit.

Permalink

stretch marks on September 26, 2016 at 7:39 AM:

Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

Permalink

mobiliario de peluqueria barato on October 05, 2016 at 1:17 AM:

Very good written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing canr wait to read more posts.

Permalink

buy with confidence on October 06, 2016 at 4:40 AM:

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing

Permalink

hacker team on October 17, 2016 at 1:12 AM:

i am continually searching for some free stuffs over the web. there are likewise a few organizations which gives free specimens. hacker team xbox

Permalink

Cortez on October 22, 2016 at 6:56 PM:

Reading your site gave me a lot of interesting informations

Permalink

Eyelash extension training on October 28, 2016 at 12:30 AM:

Your article perceftly shows what I needed to know, thanks!

Permalink

candid photography sydney on November 02, 2016 at 12:23 AM:

The amateurs must know the important tips to excel in the candid photographer sydney skills.

Permalink

Parallels desktop license key on November 04, 2016 at 5:43 AM:

Excellent blog here! Also your site loads up fast.

Permalink

photography workshops sydney on November 16, 2016 at 12:28 AM:

I would like to thank you for the efforts you have made in writing this article.

Permalink

skip hire brisbane north on November 16, 2016 at 2:07 AM:

I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit.

Permalink

lifestyle blog on December 01, 2016 at 3:02 AM:

Lifestyle blogging will definitely proof fruitful for you. Many bloggers also provides updates against subscription.

Permalink

Halal Restaurant Miami on December 16, 2016 at 1:40 AM:

Very good written article.

Permalink

Urgent Care Near Me on December 16, 2016 at 1:59 AM:

Excellent blog,Thanks for sharing.

Permalink

wholesale iphone charger on December 16, 2016 at 2:55 AM:

Really i am inspired from this post....

Permalink

360 Total Security Keygen on December 30, 2016 at 2:20 AM:

I want you to thank for your time of this wonderful read!!!

Permalink

360 Total Security Keygen on December 30, 2016 at 2:21 AM:

I want you to thank for your time of this wonderful read!!!

Permalink

360 Total Security Keygen on December 30, 2016 at 2:22 AM:

I want you to thank for your time of this wonderful read!!!

Permalink

NewBlueFX Titler Pro on January 05, 2017 at 4:29 AM:

This is a wonderful article, Given so much info in it

Permalink

futon bed on January 12, 2017 at 5:12 AM:

Here are futon bed to bring the best quality mattress for a peaceful sleep at day's end.

Permalink

Tweakbit fixmypc on February 09, 2017 at 2:58 AM:

I appreciate all the work you put into this site, helping out others with your fun and creative works.

Permalink

MB2-714 braindumps on March 13, 2017 at 2:57 AM:

Hey admin your sharing way is unique. This is fantastic site.I enjoyed reading your articles. This is truly a great read for me.

Permalink

Iobit uninstaller on March 26, 2017 at 4:28 AM:

I was interested in this topic. Thank you for sharing the link here

Permalink

Connectify hotspot pro on March 29, 2017 at 3:54 AM:

Great post,Thanks a lot for the kind of perfect topic I have not a lot of information about it but I have got an extra unique info in your unique post.

Permalink

Toyota Supra 2018 on April 04, 2017 at 12:33 AM:

Read the latest Toyota Supra sports car news, photos and Release Date.

Permalink

Proshow producer on April 09, 2017 at 6:17 AM:

Nice Web site, Continue the beneficial work. With thanks!. Super inarfmotive writing; keep it up.

Permalink

swissarmyknife on April 10, 2017 at 4:13 AM:

THE POST IS TRANSCENDENT swiss army knives

Permalink

spyhunter 4 key on April 11, 2017 at 11:15 PM:

innovative post with great information, i like it very much

Permalink

Fileviewpro on April 12, 2017 at 6:16 AM:

Very nice post.thanks for sharing such an effective post.

Permalink

Urgent Printing London on April 21, 2017 at 3:51 AM:

Very interesting blog. Alot of blogs I see these days dont really provide anything that Im interested in, but Im most definately interested in this one.

Permalink

Beautiful engagement rings on April 23, 2017 at 4:17 AM:

I am trusting the same best exertion from you later on too. Actually your exploratory writing abilities has roused me.

Permalink

Internet Download Manager Crack on April 26, 2017 at 5:02 AM:

Really amazing, Your articles were very nice and full of information. Good Job And continue to make useful articles

Permalink

Buy barcodes on April 27, 2017 at 4:16 AM:

Great Job. The article is very interesting to read. I enjoyed it to the last word. payung wagomu

Permalink

crack81 on May 06, 2017 at 6:00 AM:

Your blog is very nice thanks for sharing Then justVery nice, thanks for sharing to us Enjoyed every bit of your blog.Really looking forward to read more.

Permalink

crack82 on May 06, 2017 at 6:07 AM:

Nice post! Thanks a lot for the kind of perfect topic.I like your post. Thanks for sharing.

Permalink

crack4activator on May 06, 2017 at 6:09 AM:

I was reading the provided article with a great interest! This post is useful and informative.

Permalink

crack77 on May 06, 2017 at 6:11 AM:

I'm always happy to follow this blog post. cool various posts here on friends in social media, various comments always fulfill my social media posts. many benefits, thanks writer, keeps the spirit.

Permalink

crack44 on May 06, 2017 at 6:12 AM:

I'm always happy to follow this blog post. cool various posts here on friends in social media, various comments always fulfill my social media posts. many benefits, thanks writer, keeps the spirit.

Permalink

crack88 on May 06, 2017 at 6:13 AM:

Nice post! Thanks a lot for the kind of perfect topic.I like your post. Thanks for sharing.

Permalink

img src on May 10, 2017 at 5:12 AM:

thanks for the info and also try this free image hosting site

Permalink

geometric terrarium jar on May 18, 2017 at 12:10 AM:

Really i appreciate the effort you made to share the knowledge. This is really a great stuff for sharing. Keep it up . T
hanks for sharing.

Permalink

2017 hummer h3 on May 18, 2017 at 10:34 PM:

Nice information, very interesting. I'm very glad to find this site.

Permalink

unblock youtube on May 27, 2017 at 3:53 AM:

finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that’s what this web page is providing. unblock youtube

Permalink

Download Activation Key on May 31, 2017 at 2:02 AM:

i read your post i fell you have great writer carry on you work pleas publish more post

Permalink

top 3 car brands on June 03, 2017 at 3:21 AM:

Thanx for Sharing This useful Post, It is informative post, thank for your information

Permalink

voyance-amour-eternel.com on June 05, 2017 at 1:26 PM:

Great tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog.

Permalink

minecraft gratuit | free psn codes on June 05, 2017 at 1:33 PM:

Great to know more about the history of Kabul Times. They have been serving the country for around 54 years and have been the first and famous English newspaper in the country. Their growth have been exceptional since the beginning.

Permalink

termite pretreatment on June 07, 2017 at 2:01 PM:

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

Permalink

meilleure salle de sport montpellier on June 11, 2017 at 1:27 PM:

Very nice blog and articles I am really very happy to visit your blog. Now I am found which I actually want.Thank you and waiting for your new post.

Permalink

Megane on June 12, 2017 at 7:07 AM:

With the release of PHP 7 What are the changes and modifications to fair in this code for it to be compatible.

Permalink

mobdro free app for android on June 23, 2017 at 2:02 PM:

I am a regular visitor of Kabul times for getting the latest news and social issue related information. Glad to know the historical background from the post. You have been serving really well as a national media for the country for many years.

Permalink

Bluestacks for PC on June 29, 2017 at 11:11 PM:

I am a regular visitor of Kabul times for getting the latest news and social issue related information. Glad to know the historical background from the post. You have been serving really well as a national media for the country for many years.

Permalink

Iobit Driver Booster 3 Pro Key on July 13, 2017 at 3:22 AM:

amazing post i like your post thanks for shaaring.

Permalink

lottery subscription on July 14, 2017 at 4:58 AM:

I appreciate everything you have added to my knowledge base.Admiring the time and effort you put into your blog and detailed information you offer.Thanks.

Permalink

Company Registration on July 19, 2017 at 2:08 AM:

I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally.

Permalink

mobdro on July 19, 2017 at 8:11 AM:

I am a regular visitor of Kabul times for getting the latest news and social issue related information. Glad to know the historical background from the post. You have been serving really well as a national media for the country for many years.

Permalink

brestrogen reviews on July 22, 2017 at 8:48 AM:

I am a regular visitor of Kabul times for getting the latest news and social issue related information. Glad to know the historical background from the post. You have been serving really well as a national media for the country for many years.

Permalink

I love to learn PHP and I occasionally search new content regarding it last night i found your site and find it useful for me thanks for sharing God bless you.

Permalink

phenq on July 23, 2017 at 11:02 PM:

I am a regular visitor of Kabul times for getting the latest news and social issue related information. Glad to know the historical background from the post. You have been serving really well as a national media for the country for many years.

Permalink

Hair Care on July 24, 2017 at 5:18 AM:

Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it’s nice to find a website that details so much information about different artists. Hair Care

Permalink

driver toolkit downloading on July 25, 2017 at 3:00 AM:

Thanks you so much for providing great infomation. i have bookmarked your post.

Permalink

voyance par telephone immediate on July 27, 2017 at 4:06 AM:

I am overwhelmed by your post with such a nice topic. Usually I visit your blogs and get updated through the information you include but today’s blog would be the most appreciable. Well done! voyance par telephone immediate

Permalink

CCleaner Professional 5.28 on July 27, 2017 at 9:12 AM:

This is the very great article.the content of this post is really very amazing

Permalink

ClickHowTo on July 28, 2017 at 5:27 AM:

Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging, ClickHowTo

Permalink

TechGoo on July 28, 2017 at 6:05 AM:

Thank you for some other informative blog. Where else could I get that type of information written in such an ideal means? I have a mission that I’m just now working on. and I have been at the look out for such information. TechGoo

Permalink

voyance pas cher on July 31, 2017 at 1:25 AM:

Thanks so much for this information. I have to let you know I concur on several of the points you make here and others may require some further review, but I can see your viewpoint. voyance pas cher

Permalink

K7 Total Security Crack on August 02, 2017 at 3:38 AM:

Nice Web site, Continue the beneficial work. With thanks!. Super inarfmotive writing; keep it up.

Permalink

clicker games on August 02, 2017 at 3:53 AM:

Hey, great blog, but I don’t understand how to add your site in my rss reader. Can you Help me please?

Permalink

Dentist in Waterloo,Ontario on August 04, 2017 at 5:47 AM:

I appreciated your work very thanks
Dentist in Waterloo,Ontario

Permalink

Dentist in Brampton,Ontario on August 04, 2017 at 6:08 AM:

By far the best dentist I've been too. All the staff is beyond helpful and friendly, they make you feel like extended family.

Permalink

Universal Keygen Generator on August 08, 2017 at 9:52 PM:

This is really an informative and awesome blog to see, thanks for sharing such a terrific blog..

Permalink

download snapchat on August 16, 2017 at 9:52 AM:

Great to know more about the history of Kabul Times. They have been serving the country for around 54 years and have been the first and famous English newspaper in the country. Their growth have been exceptional since the beginning.

Permalink

download snapchat on August 16, 2017 at 9:54 AM:

I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally.

Permalink

voyance immediate on August 16, 2017 at 1:57 PM:

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog, I will keep visiting this blog very often

Permalink

kingroot for android on August 21, 2017 at 12:06 AM:

Originally, The Kabul Times twisted out in five segment and three days a week and previous to long it was shaped to a characteristic daily paper.

Permalink

Tshirt Printing London on August 21, 2017 at 10:33 PM:

Its really pleasure to read your post.Thank you so much for writing such a nice posts

Permalink

bullion embroidery on August 24, 2017 at 1:01 AM:

Fantastic work Thanks for the best was very useful for me.

Permalink

Snooker shop London on August 24, 2017 at 2:39 AM:

This post is good enough to make somebody understand this amazing thing, and Im sure everyone will appreciate this interesting things.

Permalink

india electronic visa on August 24, 2017 at 2:56 AM:

This post is good enough to make somebody understand this amazing thing, and Im sure everyone will appreciate this interesting things.

Permalink

DSA approved driving instructor on August 24, 2017 at 3:17 AM:

Very efficiently written information. It will be valuable to everyone who uses it, including myself. Thanks a lot!

Permalink

Download Free Crack on August 24, 2017 at 5:16 AM:

I like this site its so usefull and helpfull.Pretty! This was an extremely wonderful article.

Permalink

transformice game on September 05, 2017 at 2:46 AM:

I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you.

Permalink

consultation voyance par telephone on October 04, 2017 at 1:31 AM:

Good to become visiting your weblog again, it has been months for me. Nicely this article that i’ve been waited for so long. I will need this post to total my assignment in the college, and it has exact same topic together with your write-up. Thanks, good share. consultation voyance par telephone

Permalink

http://www.advancedentalcare.com/ on October 10, 2017 at 4:00 AM:

The post is written in very a good manner and it contains many useful information for me.

Permalink

http://www.advancedentalcare.com/ on October 10, 2017 at 4:39 AM:

The post is written in very a good manner and it contains many useful information for me.

Permalink

sherazpc on October 16, 2017 at 3:19 AM:

I can say this is the perfect blog for everybody who read and post here everyday.

Permalink

mystatlab on November 02, 2017 at 2:57 AM:

I want you to thank for your time of this wonderful read !!! I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog !!!

Permalink

Cyberlink Powerdvd Crack on December 06, 2017 at 11:33 AM:

I found a considerable measure of interesting information from your post. Thank you so much for your work.
Cyberlink Powerdvd Crack

Permalink

Visual Basic Homework Help on December 10, 2017 at 11:02 PM:

They are not able to finish the writing assignments on time. For some students, writing any writing assignments is able to waste their time

Permalink

العاب بنات on December 13, 2017 at 12:53 AM:

They are not able to finish the writing assignments on time. For some students, writing any writing assignments is able to waste their time

Permalink

العاب بنات on December 13, 2017 at 12:53 AM:

They are not able to finish the writing assignments on time. For some students, writing any writing assignments is able to waste their time

Permalink

Nomipie on January 14, 2018 at 12:00 PM:

Very important topic and you have delivered beautifully. I was looking for it and thanks for it.
Movavi Screen Capture Studio Crack

Permalink

Total Uninstall Crack Download on January 17, 2018 at 4:23 AM:

amazing post and the site is very nice

Permalink

Ableton Live Torrent on January 23, 2018 at 10:49 PM:

Its very impressive and proper way to describe.

Permalink

Ableton Live Torrent on January 23, 2018 at 10:49 PM:

Your site blog is very impressive

Permalink

Send Gift To Pakistan on January 26, 2018 at 2:19 AM:

Thanks for sharing.

Permalink

londonsquaredental on January 26, 2018 at 3:50 AM:

I think this is an i nformative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.

Permalink

smilezone on January 26, 2018 at 6:23 AM:

Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading.
dentist near me Edmonton

Permalink

edgemontdentalclinic on January 26, 2018 at 7:37 AM:

This is my first t e i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work
southwest Edmonton dentist

Permalink

mysmilefamilydentall on January 26, 2018 at 8:24 AM:

Your website is really cool and this is a great inspiring article.
Dentist in Northwest Edmonton

Permalink

product key on February 05, 2018 at 7:39 AM:

Wow, Its really wonderful to read this article,you can dowmload here more and more........
WavePad Sound Editor 7.13 Crack
WavePad Sound Editor 7.13 Crack multidimensional and powerful latest audio editing software that is fully compatible and featured professional audio and music editor for Windows as well as Mac.It is the greatest tool for edit music, sound, song, and everything if you wants.

Permalink

product key on February 05, 2018 at 7:40 AM:

Its really wonderful to read this article,you can dowmload here more and more
iPhone Backup Extractor Crack
iPhone Backup Extractor Crack is a best and powerful backup solution software which help you to recover lost iPhone files like calendar events, notes, SMS messages and app data from iTunes and iCloud backup files.

Permalink

Clean Master full download on February 12, 2018 at 3:19 AM:

amazing site i like use it very time and thanks for sharing the idea

Permalink

Barbous on February 15, 2018 at 3:24 PM:

I should describe any thing i want learn him in php, as any new programmer know few things, if we code something big hiw will gets more complex. go here

Permalink

azaankhan on February 24, 2018 at 2:30 AM:

ESET NOD32 Antivirus 11.0.159.5 Final Full Crack
I found a considerable measure of interesting data on your blog.
Thank you for sharing this good information. Keep it up.

Permalink

website games banat on March 12, 2018 at 4:28 PM:

I found a considerable measure of interesting data on your blog.
Thank you for sharing this good information. Keep it up.:::

Permalink

Suicokeonline on August 20, 2018 at 2:13 AM:

Thank you for this incredibly amazing blog. This is the right place where there is something for everyone! Thanks for sharing this post..!!

Permalink

Suicokeonline on August 21, 2018 at 12:09 AM:

Don't shortchange your feet,It has a long way to go.Give it a pair of comfortable shoes.

Permalink

Suicokeonline on August 22, 2018 at 2:46 AM:

Don't shortchange your feet,It has a long way to go.Give it a pair of comfortable shoes.Make the road ahead smoother.

Permalink

Suicokeonline on August 23, 2018 at 12:07 AM:

Thank you for this incredibly amazing blog. This is the right place where there is something for everyone! Thanks for sharing this post..!!

Permalink

Suicokeonline on August 23, 2018 at 7:58 PM:

Thank you for this incredibly amazing blog. This is the right place where there is something for everyone! Thanks for sharing this post..!!

Permalink

Suicokeonline on August 23, 2018 at 7:59 PM:

This is an online sales site,There are all kinds of sandals.

suicoke

Permalink

rogervivier on August 26, 2018 at 8:47 PM:

Don't shortchange your feet,It has a long way to go.Give it a pair of comfortable shoes.Make the road ahead smoother.

Permalink

manolo blahnik on August 28, 2018 at 1:43 AM:

Thank you for this incredibly amazing blog. This is the right place where there is something for everyone! Thanks for sharing this post..!!

Permalink

releaseloaddotcom on August 28, 2018 at 3:37 AM:

I'm agree with your post and i can understand with your words thanks for the sharing

Permalink

manolo blahnik on August 28, 2018 at 8:40 PM:

When setting out on a long walk, always wear suitable boots.So you can go further.

Permalink

Marketing Research Assignments Help on August 29, 2018 at 3:55 AM:

This A Good Way To Appreciate The Teacher As They Put Their Efforts To Train Students. UK Dissertation Writers Appreciates The Teachers.

Permalink

Company Formation on August 29, 2018 at 4:16 AM:

Only Professional Writers Can Make This Kind Of Material, Cheers

Permalink

Mouonline on August 29, 2018 at 7:21 PM:

When setting out on a long walk, always wear suitable boots.So you can go further.

Permalink

Post Comments

If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.

Name:

Email Address:

Website:

Comments:

Check this box if you hate spam.