Mam plik html, który ładuję poprzez DOMDocument
, w którym wykonuję niektóre manipulacje DOM, a następnie wyprowadzam kod HTML z saveHTML
.Zapobieganie zdejmowaniu pustych tagów przez DOMDocument
Problemem jest to, że białe przestrzenie po tagach wejściowych są usuwane, tutaj jest 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();
on rozłożony na spacje po innych tagów próbowałem (<br>
, <hr>
) z wyjątkiem tagów w <head>
.
Próbowałem ustawić wartość true dla formatOutput
, ale to tylko zatrzymało spacje przed zamykającym tagiem.
Czy istnieje sposób, aby DOMDocument zachował białe przestrzenie po mojej <input>
s?
Przetłumacz białe spacje na " " lub " ". Nieprzerwane spacje nie ulegają zwinięciu. –
@JeremyJStarcher to nie jest zwinięty jego usunięcie, również szukałem rozwiązania, które nie wymaga zmiany znaczników. – Musa