मैं इस का उपयोग किसी पाठ स्ट्रिंग के साथ एंकर को बदलने के लिए ...
function replaceAnchorsWithText($data) {
$regex = '/(<a\s*'; // Start of anchor tag
$regex .= '(.*?)\s*'; // Any attributes or spaces that may or may not exist
$regex .= 'href=[\'"]+?\s*(?P<link>\S+)\s*[\'"]+?'; // Grab the link
$regex .= '\s*(.*?)\s*>\s*'; // Any attributes or spaces that may or may not exist before closing tag
$regex .= '(?P<name>\S+)'; // Grab the name
$regex .= '\s*<\/a>)/i'; // Any number of spaces between the closing anchor tag (case insensitive)
if (is_array($data)) {
// This is what will replace the link (modify to you liking)
$data = "{$data['name']}({$data['link']})";
}
return preg_replace_callback($regex, array('self', 'replaceAnchorsWithText'), $data);
}
संभव डुप्लिकेट [आप कारण है कि यह एक regex के साथ XML और HTML पार्स करने के लिए कठिन है के कुछ उदाहरण दे सकते हैं?] (Http://stackoverflow.com/questions/701166/can-you-provide-some -examples-of-why-it-hard-to-parse-xml-and-html-with-a-rege) –
संभावित डुप्लिकेट [XHTML स्वयं निहित टैग को छोड़कर RegEx मिलान खुले टैग] (http: // stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) –