<?php

$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';
$dom = new DOMDocument;
@$dom->loadHTML($str, LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD);

$xp = new DOMXPath($dom);
$links = $xp->query('//a');

foreach ($links as $link) {
	$link->parentNode->removeChild($link);
    //$href= $link->getAttribute('href');
    //$txt = $dom->createTextNode($href . ' ' . $link->nodeValue);
    //$link->parentNode->replaceChild($txt, $link);
 }
echo preg_replace('/^<p>([^<>]*)<\/p>$/', '$1', @$dom->saveHTML());