1

I'm just curious as to why this works:

$config = array('wrap' => 0,'show-body-only' => TRUE,);

$str = '<p>Hello World!';

$tidy = tidy_parse_string($str, $config);
tidy_clean_repair($tidy);
echo (htmlentities($tidy)); //outputs <p>Hello World!</p> 

while this doesn't:

$config = array('wrap' => 0,'show-body-only' => TRUE,);

$str = 'Hello World!</p>';

$tidy = tidy_parse_string($str, $config);
tidy_clean_repair($tidy);
echo (htmlentities($tidy)); //outputs Hello World! 
1
  • I imagine its because tidy completes orphan open tags and deletes orphan closing tags. But why it was coded like that I have no idea. Maybe its because of the direction when its parsed. it would have to go back to open those tags. Commented Aug 30, 2010 at 3:45

2 Answers 2

3

I believe if you put <p> that most programs accept that as "until the end of the line" but if you put a </p> it is not able to match where it started and disregards it.

(But I am not 100% sure)

Sign up to request clarification or add additional context in comments.

Comments

1

the tidy_clean_repair() function tries to fix the code for you. but of course the function is not perfect and could not guess precisely what you wanted to write in the second example. so it probably just ripped it off

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.