我有一個html文件,我通過DOMDocument
加載,其中我通過一些DOM操作輸出了帶有saveHTML
的html。防止DOMDocument在空標籤後剝離空白
的問題是,輸入標籤後的空格都去掉,這裏是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,但只保留了空間關閉標籤之前。
有沒有一種方法,使DOM文檔保存後,我的<input>
S中的空格?
翻譯白色空格' '或'' 。非破壞空間不會摺疊。 –
@JeremyJStarcher它沒有倒塌其刪除,還我一直在尋找不涉及改變標記的解決方案。 – Musa