Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-10-2009, 05:58 AM help with PHP tidy
bmcoll3278's Avatar
Super Talker

Posts: 118
Name: Brian Collins
Trades: 0
Hey guys
I am building a page for myself and friends that will clean up html using php tidy

It works fine but I can not figure out hot to ad indents to the outputed html. I am very new to the tidy workings. here is the code i am using

Code:
<?php

$file= $_POST['file'];


$tidy = tidy_parse_string($file);
$tidy->_error_count;


    echo "The following errors were detected:<br>";
    

preg_match_all('/^(?:line (\d+) column (\d+) - )?(\S+): (?:\[((?:\d+\.?){4})]:)
?(.*?)$/m', $tidy->errorBuffer, $tidy_errors, PREG_SET_ORDER);

$malestr = str_replace("line","\nline:",$tidy->errorBuffer);

$article1=nl2br(htmlentities($malestr));
echo "$article1<br>";

$tidy->CleanRepair();
  
echo"<textarea cols=\"80\"rows=\"30\">$tidy</textarea>";
?>
I will feel dumb if it is an easy fix but please if you can tell me how.
I have been trying for hours now.
__________________
I hope to build a site with something for every one

Please login or register to view this content. Registration is FREE

Last edited by bmcoll3278; 09-10-2009 at 06:02 AM..
bmcoll3278 is offline
Reply With Quote
View Public Profile Visit bmcoll3278's homepage!
 
 
Register now for full access!
Old 09-18-2009, 02:37 AM Re: help with tidy
bmcoll3278's Avatar
Super Talker

Posts: 118
Name: Brian Collins
Trades: 0
Since no one has answered this and that is strange on this form I thought that I would share the answer now that I figured it out.

Code:
<?php

$file= $_POST['file'];


$tidy = tidy_parse_string($file);


$tidy->diagnose();
    echo "The following errors/warnings were detected:<br>";
    

preg_match_all('/^(?:line (\d+) column (\d+) - )?(\S+): (?:\[((?:\d+\.?){4})]:)
?(.*?)$/m', $tidy->errorBuffer, $tidy_errors, PREG_SET_ORDER);

$malestr = str_replace("line","\nline:",$tidy->errorBuffer);

$article1=nl2br(htmlentities($malestr));
echo "$article1<br>";
ob_start();

echo"$file";

$html = ob_get_clean();
// Specify configuration
$config = array(
          'indent'         => true,
          'output-xhtml'   => true,
          'wrap'           => 200,
          'doctype'        => Transitional
);

// Tidy
$tidy = new tidy;
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();

// Output
echo"<h2>Here is your cleaned html</h2>";
echo"<textarea cols=\"80\"rows=\"30\">$tidy</textarea>";
?>
hope it can help someone.
__________________
I hope to build a site with something for every one

Please login or register to view this content. Registration is FREE
bmcoll3278 is offline
Reply With Quote
View Public Profile Visit bmcoll3278's homepage!
 
Old 09-18-2009, 03:12 AM Re: help with tidy
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
I don't know anything about tidy, but if you want tabs and lines to appear in your output use the \t \n characters:

PHP Code:
echo "\t"//tab
echo "\n"//new line 
Note that using double quotes is mandatory, using single quotes will output the literal \t and \n.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-18-2009, 07:56 PM Re: help with tidy
bmcoll3278's Avatar
Super Talker

Posts: 118
Name: Brian Collins
Trades: 0
I have played with the code and got something that works very well it will give a textarea with a list of all errors found and a text area with the html corrected to XHTML1.0 trans and the second text area even auto highlights on mouse click.

I did not know tidy but a crash course helped some.

Code:
<?php

$file= $_POST['file'];


$tidy = tidy_parse_string($file);


$tidy->diagnose();
    echo "The following errors/warnings were detected:<br>
<textarea cols=\"80\"rows=\"30\"onclick=\"javascript:select();\">";
    


echo tidy_get_error_buffer($tidy);
/* or in OO: */
echo $tidy->errorBuffer;

echo"</textarea>";
ob_start();

echo"$file";

$html = ob_get_clean();
// Specify configuration
$config = array(
          'indent'         => true,
          'output-xhtml'   => true,
          'wrap'           => 200,
          'doctype'        => Transitional
);

// Tidy
$tidy = new tidy;
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();

// Output
echo"<h2>Here is your cleaned html <br>(W3C//DTD XHTML 1.0 Transitional)doc type</h2>";
echo"<textarea cols=\"80\"rows=\"30\"onclick=\"javascript:select();\">$tidy</textarea>";
?>
I hope this code can be of help to others.
__________________
I hope to build a site with something for every one

Please login or register to view this content. Registration is FREE
bmcoll3278 is offline
Reply With Quote
View Public Profile Visit bmcoll3278's homepage!
 
Reply     « Reply to help with PHP tidy
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13941 seconds with 12 queries