fork(1) download
  1. <?php
  2.  
  3. $str = 'Try to remove the link text from the content <a href="#">links in it</a> Try to remove the link text from the content <a href="#">testme</a> Try to remove the link text from the content';
  4. $dom = new DOMDocument;
  5. @$dom->loadHTML($str, LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD);
  6.  
  7. $xp = new DOMXPath($dom);
  8. $links = $xp->query('//a');
  9.  
  10. foreach ($links as $link) {
  11. $link->parentNode->removeChild($link);
  12. //$href= $link->getAttribute('href');
  13. //$txt = $dom->createTextNode($href . ' ' . $link->nodeValue);
  14. //$link->parentNode->replaceChild($txt, $link);
  15. }
  16. echo preg_replace('/^<p>([^<>]*)<\/p>$/', '$1', @$dom->saveHTML());
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Try to remove the link text from the content  Try to remove the link text from the content  Try to remove the link text from the content