要素に対して簡単な操作を実行しようとしています。 HTMLファイルが読み込まれ、要素のIDがはっきりと表示されます。以下のエラーログには警告が表示されます。それは警告なので、要素操作コードを実行しないと思います。私は警告を押さえることができます。ええ、エコーはどこにも表示されません。PHP DOMDocumentを使用して要素を操作できないのはなぜですか?
PHP
$doc = new DOMDocument();
$doc->loadHTMLFile('../index.html');
$elem = $doc->getElementById('message');
var_dump("elem=" . $elem);
if ($result == 1) {
$elem->innerHTML = 'File uploaded.';
} else {
$elem->setAttribute("background-color", "red");
$elem->innerHTML = 'Upload failed.';
}
HTML(index.htmlを)
<html lang="en" data-ng-app="wtApp">
<head>
<meta charset="utf-8" />
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<title>Writer's Tryst</title>
<link href='https://fonts.googleapis.com/css?family=Lobster+Two:700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Ubuntu:400,500' rel='stylesheet' type='text/css'>
<link href='css/main.css' rel='stylesheet' type='text/css' />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="frainversegment" content="!" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" />
<link rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.css" />
<link rel="stylesheet" href="css/main.css" />
<link rel="shortcut icon" href="img/Hands_of_God_and_Adam.png" />
<!--
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-15499108-1");
pageTracker._trackPageview();
} catch (err) { }
</script>
</head>
<body>
<header>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#Writers-Tryst">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Writers-Tryst</a>
</div>
<div class="collapse navbar-collapse" id="Writers-Tryst">
<ul class="nav navbar-nav">
<li class="active"><a id="homepage" href="#"><i class="glyphicon glyphicon-home"></i> Home</a></li>
<li><a href="#writers" class="glyphicon glyphicon-book"> Writers</a></li>
<li><a href="#enablers" class="glyphicon glyphicon-thumbs-up"> Enablers</a></li>
<li><a href="#about" class="glyphicon glyphicon-info-sign"> About</a></li>
<li><a href="#contact" class="glyphicon glyphicon-envelope"> Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#log-in"><i class="glyphicon glyphicon glyphicon-log-in"></i> Log-In</a></li>
<li><a id="create-account-link" href="#create-account"><i class="glyphicon glyphicon-user"></i> Create Account</a></li>
<li class="dropdown">
<a href="#" id="drop-toggle-1" class="dropdown-toggle glyphicon glyphicon-user" data-toggle="dropdown" role="button" data-aria-haspopup="true" data-aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#update-profile">Update profile</a></li>
<li><a href="#manage-uploads">Manage uploads</a></li>
</ul>
</li>
<li ><a id="reset-pwd-link" href="#reset-pwd"></a></li>
</ul>
</div>
</div>
</nav>
</header>
<div>
<p id="message"></p>
<div id="main" class="content">
<!-- angular templating -->
<!-- this is where content will be injected -->
<div data-ng-view></div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/common.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="js/pages.js"></script>
<script type="text/javascript" async src="//platform.twitter.com/widgets.js"></script>
</body>
</html>
[19-May-2016 13:31:53 UTC] PHP Warning: DOMDocument::loadHTMLFile(): Tag header invalid in ../index.html, line: 42 in /home/deje/public_html/writers-tryst/php/writers.php on line 83
ダウン投票の理由を説明してください。 –
あなたはユーザーのブラウザのライブドームを取得しようとしていませんか?あなたがPHPですることはできませんので。 – Gant
** HTML5タグ**のPHP DOMDocumentエラー/警告**(http://stackoverflow.com/questions/6090667/php-domdocument-errors-warnings-on-html5-tags) – Chay22