Skip to main content
Formatted the code
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132

The purpose of this function is to simply wrap the first occurrence of the keyword in bold tags. I'm getting an error on the line marked below.

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: error parsing attribute name in Entity, line: 4 in C:\xampplite\htdocs\testsite\wp-content\plugins\mylugin\test.php on line 40

Is this the correct way to pass the post_content object?

add_filter('wp_insert_post_data', 'my_bold_keyword' );

add_filter('wp_insert_post_data', 'my_bold_keyword' );
function my_bold_keyword($content){
            $myKeyword = "test 123";
    $d = new DOMDocument();
    $d->loadHTML($content['post_content']); //ERROR OCCURS HERE
    $x = new DOMXpath($d);
    $Matches = $x->query("//text()[contains(.,$myKeyword) and not(ancestor::h1) and not(ancestor::h2) and not(ancestor::h3) and not(ancestor::h4) and not(ancestor::h5) and not(ancestor::h6)]");
        if($Matches && $Matches->length > 0){
      $myText = $Matches->item(0);
      // need to wrap #myText in <b> wrapper
    }
    return $content;
}

The purpose of this function is to simply wrap the first occurrence of the keyword in bold tags. I'm getting an error on the line marked below.

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: error parsing attribute name in Entity, line: 4 in C:\xampplite\htdocs\testsite\wp-content\plugins\mylugin\test.php on line 40

Is this the correct way to pass the post_content object?

add_filter('wp_insert_post_data', 'my_bold_keyword' );

function my_bold_keyword($content){
            $myKeyword = "test 123";
    $d = new DOMDocument();
    $d->loadHTML($content['post_content']); //ERROR OCCURS HERE
    $x = new DOMXpath($d);
    $Matches = $x->query("//text()[contains(.,$myKeyword) and not(ancestor::h1) and not(ancestor::h2) and not(ancestor::h3) and not(ancestor::h4) and not(ancestor::h5) and not(ancestor::h6)]");
        if($Matches && $Matches->length > 0){
      $myText = $Matches->item(0);
      // need to wrap #myText in <b> wrapper
    }
    return $content;
}

The purpose of this function is to simply wrap the first occurrence of the keyword in bold tags. I'm getting an error on the line marked below.

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: error parsing attribute name in Entity, line: 4 in C:\xampplite\htdocs\testsite\wp-content\plugins\mylugin\test.php on line 40

Is this the correct way to pass the post_content object?

add_filter('wp_insert_post_data', 'my_bold_keyword' );
function my_bold_keyword($content){
  $myKeyword = "test 123";
  $d = new DOMDocument();
  $d->loadHTML($content['post_content']); //ERROR OCCURS HERE
  $x = new DOMXpath($d);
  $Matches = $x->query("//text()[contains(.,$myKeyword) and not(ancestor::h1) and not(ancestor::h2) and not(ancestor::h3) and not(ancestor::h4) and not(ancestor::h5) and not(ancestor::h6)]");
  if($Matches && $Matches->length > 0){
    $myText = $Matches->item(0);
    // need to wrap #myText in <b> wrapper
  }
  return $content;
}
Source Link
Scott B
  • 5.7k
  • 14
  • 94
  • 148

Error passing post_content to function

The purpose of this function is to simply wrap the first occurrence of the keyword in bold tags. I'm getting an error on the line marked below.

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: error parsing attribute name in Entity, line: 4 in C:\xampplite\htdocs\testsite\wp-content\plugins\mylugin\test.php on line 40

Is this the correct way to pass the post_content object?

add_filter('wp_insert_post_data', 'my_bold_keyword' );

function my_bold_keyword($content){
            $myKeyword = "test 123";
    $d = new DOMDocument();
    $d->loadHTML($content['post_content']); //ERROR OCCURS HERE
    $x = new DOMXpath($d);
    $Matches = $x->query("//text()[contains(.,$myKeyword) and not(ancestor::h1) and not(ancestor::h2) and not(ancestor::h3) and not(ancestor::h4) and not(ancestor::h5) and not(ancestor::h6)]");
        if($Matches && $Matches->length > 0){
      $myText = $Matches->item(0);
      // need to wrap #myText in <b> wrapper
    }
    return $content;
}