A html formatting script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

A html formatting script

Post by Todd_Z »

I'm looking for a script that when I feed it a file, it reads through the html and source formats it.... Anyone seen one of these? Thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

describe: "formats it"

http://www.domain.com?page=htmlsource.html

Code: Select all

<?php
$page = file_get_contents($_GET['page']);

echo $page;

?>
Note: You will want to validate where the file is coming from first else users would be able to run harmful errors.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

For example, it would turn
<table><tr>
<td><B></b>random text</td></tr>
</table>

to =>

<table>
<tr>
<td>Random text</td>
</tr>
</table>

With the right spacing, which i can't do here...
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Phenom wrote:describe: "formats it"
I think he means "clean up the code" like indent and put tags on their own lines like

Code: Select all

<table><tr><td>stuff</td></tr></table>
would format to

Code: Select all

<table>
  <tr>
    <td>stuff</td>
  </tr>
</table>
jl
Forum Commoner
Posts: 53
Joined: Tue Nov 09, 2004 12:05 am

Post by jl »

User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Hmmm.... well that seems to be a program, im looking for a script at runtime... like a php script in itself that i can have read the url given and format it.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

http://www.php.net/tidy no need to spawn a differenct process
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

It looks like that has no spacing, i'm really looking for a script, not built in functions so that i can tweak it to make the style how i want it to be...
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Bunch on google... "html code beautifier" will bring back a bunch. Most you gotta pay for, if not all.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Im looking for a runtime script, those all look like programs...
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

have you tried hotscripts.com ?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

tidy can clean up... and make it valid xhtml.. which is xml... thus you can write an xslt that transforms it to whatever you like..
Post Reply