Tidy and PHP code question

imagine7xy used Ask the Experts™
Hello, I have tried using number tools to tidy up my PHP/HTML code correctly. The problem is when I have a line like:

<a href="http://<?php echo $row11['ad_link']; ?>"><img src="<?php echo $row11['photo']; ?>"  title="<?php echo $row11['ad_desc']; ?>" /></a>

It will come out like:

<a href="http://%3C?=$row11['ad_link'];?%3E"><img src=
"%3C?=$row11['photo'];?%3E" title=

Is there any possible way to FIX this please? Thank you!

II've tried using HTML Tidy (CLI version), PHP Tidy package, hindent, and htb so far. Are there any configuration options I must set to make ANY of work this correctly? Or recommendation for different program?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Just wondering, Have you tried http://www.phpformatter.com/ ? or an online formatter wouldn't suit your needs ?
Use html_entity_decode: http://www.php.net/manual/en/function.html-entity-decode.php
<a href="http://<?php echo html_entity_decode($row11['ad_link']); ?>"><img src="<?php echo html_entity_decode($row11['photo']); ?>"  title="<?php echo html_entity_decode($row11['ad_desc']); ?>" /></a>

Open in new window

Ignore my first post... one option is to replace the PHP start/end tags before tidying and then replace back:

From http://stackoverflow.com/questions/1262420/configure-html-tidy-to-ignore-php-short-start-and-end-tags-when-inside-html-attri
You could pre-process your php:

by adding comments by converting <? to <!--<?, and ?> to ?>-->

<input value='<?=$variable?>'>

would become

<input value='<!--<?=$variable?>-->'>

after running HTMLtidy, you would do the opposite.

pre-process by adding comment tags
run HTMLtidy
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


That is really ghetto though. You would think there would be one decent PHP/HTML formatter out there... I finally decided to just use ob_start, however, Tidy is REALLY buggy with PHP, I don't know if I trust it.


remorina:I already have a really nice PHP formatter that is part of PEAR called PHP_Beautifier, I just don't have a darn HTML one that doesn't mess with PHP. Even PHP's own Tidy module messes up PHP.
Top Expert 2010
Have you tried http://www.mycoolform.com/index.php?lang=en-us,en;q=0.5

I personally use Visual Studio, which can still format php files, I just rename them to .htm and format them then it only takes a minute to make it suit my standards, second option is DreamWeavers code format which still works well and is also configurable, they both wouldn't mess with actual code or characters/symbols

Dreamweaver is great for code formatting, but it's not free :(

Netbeans is, though, and it's also a very very good editor! http://netbeans.org/



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial