我有一个加载的 html 文件,DOMDocument
在该文件中我对 html 的输出进行了一些 DOM 操作saveHTML
。
问题是输入标签后的空格被删除,这里是HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="/style.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
window.jQuery || document.write(unescape('%3cscript src="/script/jquery.min.js"%3e%3c/script%3e'));
</script>
</head>
<body>
<div>
<div>
<form method="post" action="/register/">
<label>First name: <input type="text" name="firstname"></label>
<label>Last name: <input type="text" name="lastname"></label>
<label>Date of birth: <input type="date" name="dateofbirth"></label>
<label>Address: <input type="text" name="address"></label>
<label>Phone number: <input type="text" name="phonenumber"></label>
<label>Sex: <input type="text" name="sex"></label>
<label>Email address: <input type="email" name="email"></label>
<label>Account password: <input type="password" name="password"></label>
<input id="register-button" type="submit" value="Register">
<input type="reset" value="Reset">
<input type="button" value="Cancel">
</form>
</div>
</div>
</body>
</html>
PHP
$template_file = $_SERVER['DOCUMENT_ROOT']."/application/template/template.html";
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadHTMLFile($template_file);
/* dom manipulation, importing and appending nodes from other documents etc */
echo $doc->saveHTML();
除了. _ <br>
_<hr>
<head>
我尝试设置formatOutput
为 true ,但只保留结束标记前的空格。
有没有办法让 DOMDocument 在我的 s 之后保留空格<input>
?