简体   繁体   English

PHP整理和结束标签查询

[英]PHP Tidy & closing tags query

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! 

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. 我相信如果你把<p>大多数程序都接受为“直到行尾”,但是如果你放了一个</p>它就无法匹配它开始的地方并忽略它。

(But I am not 100% sure) (但我不是100%肯定)

the tidy_clean_repair() function tries to fix the code for you. tidy_clean_repair()函数尝试为您修复代码。 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 所以它可能只是把它撕掉了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM