我真的在这里抓稻草。我不编写代码,并且在编辑模板时,我的PHP电子邮件扩展可以很好地解决这些错误。我的供应商位于谁知道什么时区,并且反应迟钝。除了显而易见的-更改扩展名,更改供应商等之外,任何PHP人士都可以查看此代码块并告诉我哪里出了问题。我不知道如果脱离上下文,这是否有意义。错误是PHP注意:试图从第1344行开始获取非对象的属性。这是从1344到1370的代码块。很显然,当不能选择HTML时,这与切换到纯文本有关。再次,在这里抓住了稻草,但是对于知识渊博的人来说,stackoverflow非常可靠。
我正在重新粘贴代码以包含一个更完整的块。我还在行中添加了注释,以指示四个警告出现的位置。他们看起来像这样: //下一行是错误一-1344行注意:试图获取非对象的属性
谢谢
<?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;
}
}
?>
答案 0 :(得分:0)
从$node
进入函数的private function _html_to_plain_text($node)
变量之类的声音不是正确的变量类型。可能是int
,string
,array
或null
,而不是应该的对象/类。您可能需要查看调用该函数的代码,而不是函数本身。
使用PHP进行调试本身就是一项技能。
var_export($node);
语句,以便您进行检查。