0

$child_url = 'https://c2code.jagdish.info/';
$postid = trim(123);
 if(!empty($vcontent_post_content)){
          $content = apply_filters('the_content', $vcontent_post_content);
       $content = str_replace(']]>', ']]>', $content);
       $dom = new DOMDocument;
       //$dom->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
       $dom->loadHTML($content);
    $links = $dom->getElementsByTagName('a');
               //Loop through each <a> tags and replace them by their text content    
       for ($i = $links->length - 1; $i >= 0; $i--) {
           $linkNode = $links->item($i);
           $url = $links->item($i)->getAttribute("href");
           if (strpos($url, $child_url) !== false) {
            $lnkText = $linkNode->textContent;
            if(!empty($lnkText)){
             $newTxtNode = $dom->createTextNode($lnkText);
             $linkNode->parentNode->replaceChild($newTxtNode, $linkNode);	
            }
           }
       }
               $content = utf8_decode($dom->saveHTML($dom->documentElement));
       $content = str_replace(array('<html><body>','</body></html>'),'',$content);
       global $wpdb;
      $data_update = array('post_content' => $content);
     $data_where  = array('ID' => $postid);
     $updt = $wpdb->update($tableName , $data_update, $data_where);
     if($updt){
      $updt_db = 'Yes';
     }
         }

Jagdish Sarma Asked question March 7, 2023
Add a Comment