Jump to content

Removing the <a> tag with regex


BillyBoB

Recommended Posts

I'm need to remove the <a> tag from any text but leave all other tags.

The <a> tag could include any possible attributes including those like id, class, or href. If you can help me that would be great or just point me in the right direction.

I have been working on this for hours still nothing comes up.

 

Link to comment
Share on other sites

<?php

$str = 'Some <b>Text </b><span><a href="1.html">
11</a><A href="1.htm">
ewfwm</a></span> <u>Hello</u>';

$pattern = "/<a ?.*<\/a>/si";
$replacement = "";
echo preg_replace($pattern, $replacement, $str);

?>

 

Orio.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.