tidy_repair_string removes end line break (\n or \r)

838 views Asked by At
$HTMLcodeOutput = tidy_repair_string($HTMLcode, array('show-body-only' => true, 'indent' => true));

will remove $HTMLcode' end of line. Ex :

that's in the main box



##What does it do ?

it does everything



##Output:

Will output

that's in the main box ##What does it do ? it does everything
##Output: I will giv ea a grat output

This wouldn't be a problem if this string wasn't echoed into a < pre > tag thereafter. Thus, the \n or \r character IS important. I had a look at the documentation, but couldn't find anything obvious.

Is there any way to keep these line return characters ?

(Adding tags before using tidy string repair is a bad idea, as it will result in echoing the <pre> tags visible in the browser, as string (decoded), and not as tags.)

1

There are 1 answers

0
Matt On BEST ANSWER

If I've understood correctly, you are trying to format html for human readability, and you don't want to use "pre" tags to force tidy to preserve whitespace because you will be running the output of tidy through htmlspecialchars before outputting it to the browser.

Why don't you just remove those "pre" tags after cleaning? It would look like this:

$config = array('show-body-only' => true, 'indent' => true);
$HTMLcodeOutput = tidy_repair_string('<pre>'.$HTMLcode.'</pre>', $config);
$HTMLcodeOutput = substr($HTMLcodeOutput, 5, -6);