私は本当にここでストローをつかんでいます。私はコードを書いていませんが、PHP の電子メール拡張機能は、テンプレートを編集するときにこれらのエラーが発生することを除けば、うまく機能します。私のベンダーはタイムゾーンが不明で、非常に反応がありません。明らかな - 拡張機能の変更、ベンダーの変更などに加えて、PHP 関係者のいずれかがこのコード ブロックを見て、何が問題なのか教えてもらえますか? 文脈から外して意味があるかどうかはわかりません。The Errors are PHP Notice: Trying to get property of non-object starting at line 1344. Here is a block of code from 1344 to 1370. HTML がオプションではない場合にプレーン テキストに切り替えることと明らかに関係があります。繰り返しますが、ここでストローをつかみますが、知識のある人々に関しては、stackoverflowはかなり堅実です.
より完全なブロックを含めるためにコードを再貼り付けています。また、4 つの警告が表示される場所を示すために、行にコメントを追加しました。//NEXT LINE IS ERROR ONE - LINE 1344 Notice: Trying to get property of non-object
ありがとうございました
<?php
public static function isHTML($str) {
$html = array('A','ABBR','ACRONYM','ADDRESS','APPLET','AREA','B','BASE','BASEFONT','BDO','BIG','BLOCKQUOTE',
'BODY','BR','BUTTON','CAPTION','CENTER','CITE','CODE','COL','COLGROUP','DD','DEL','DFN','DIR','DIV','DL',
'DT','EM','FIELDSET','FONT','FORM','FRAME','FRAMESET','H1','H2','H3','H4','H5','H6','HEAD','HR','HTML',
'I','IFRAME','IMG','INPUT','INS','ISINDEX','KBD','LABEL','LEGEND','LI','LINK','MAP','MENU','META',
'NOFRAMES','NOSCRIPT','OBJECT','OL','OPTGROUP','OPTION','P','PARAM','PRE','Q','S','SAMP','SCRIPT',
'SELECT','SMALL','SPAN','STRIKE','STRONG','STYLE','SUB','SUP','TABLE','TBODY','TD','TEXTAREA','TFOOT',
'TH','THEAD','TITLE','TR','TT','U','UL','VAR');
return preg_match("~(<\/?)\b(".implode('|', $html).")\b([^>]*>)~i", $str, $c);
}
private function _html_to_plain_text($node) {
if ($node instanceof DOMText) {
return preg_replace("/\\s+/im", " ", $node->wholeText);
}
if ($node instanceof DOMDocumentType) {
// ignore
return "";
}
// Next
//NEXT LINE IS ERROR ONE - LINE 1344 Notice: Trying to get property of non-object
$nextNode = $node->nextSibling;
while ($nextNode != null) {
if ($nextNode instanceof DOMElement) {
break;
}
$nextNode = $nextNode->nextSibling;
}
$nextName = null;
if ($nextNode instanceof DOMElement && $nextNode != null) {
$nextName = strtolower($nextNode->nodeName);
}
// Previous
//NEXT LINE IS ERROR TWO - LINE 1357 Notice: Trying to get property of non-object
$nextNode = $node->previousSibling;
while ($nextNode != null) {
if ($nextNode instanceof DOMElement) {
break;
}
$nextNode = $nextNode->previousSibling;
}
$prevName = null;
if ($nextNode instanceof DOMElement && $nextNode != null) {
$prevName = strtolower($nextNode->nodeName);
}
//NEXT LINE IS ERROR THREE - LINE 1369 Notice: Trying to get property of non-object
$name = strtolower($node->nodeName);
// start whitespace
switch ($name) {
case "hr":
return "------\n";
case "style":
case "head":
case "title":
case "meta":
case "script":
// ignore these tags
return "";
case "h1":
case "h2":
case "h3":
case "h4":
case "h5":
case "h6":
// add two newlines
$output = "\n";
break;
case "p":
case "div":
// add one line
$output = "\n";
break;
default:
// print out contents of unknown tags
$output = "";
break;
}
// debug $output .= "[$name,$nextName]";
//NEXT LINE IS ERROR FOUR - LINE 1408 Notice: Trying to get property of non-object
if($node->childNodes){
for ($i = 0; $i < $node->childNodes->length; $i++) {
$n = $node->childNodes->item($i);
$text = $this->_html_to_plain_text($n);
$output .= $text;
}
}
// end whitespace
switch ($name) {
case "style":
case "head":
case "title":
case "meta":
case "script":
// ignore these tags
return "";
case "h1":
case "h2":
case "h3":
case "h4":
case "h5":
case "h6":
$output .= "\n";
break;
case "p":
case "br":
// add one line
if ($nextName != "div")
$output .= "\n";
break;
case "div":
// add one line only if the next child isn't a div
if (($nextName != "div" && $nextName != null) || ($node->hasAttribute('class') && strstr($node->getAttribute('class'), 'emailtemplateSpacing')))
$output .= "\n";
break;
case "a":
// links are returned in [text](link) format
$href = $node->getAttribute("href");
if ($href == null) {
// it doesn't link anywhere
if ($node->getAttribute("name") != null) {
$output = "$output";
}
} else {
if ($href == $output || ($node->hasAttribute('class') && strstr($node->getAttribute('class'), 'emailtemplateNoDisplay'))) {
// link to the same address: just use link
$output;
} else {
// No display
$output = $href . "\n" . $output;
}
}
// does the next node require additional whitespace?
switch ($nextName) {
case "h1": case "h2": case "h3": case "h4": case "h5": case "h6":
$output .= "\n";
break;
}
default:
// do nothing
}
return $output;
}
}
?>