I’m trying to replace a href and I have the following code : <a href="http://www.mysite.com" target="_blank">My site</a>
with that :
$textarea_content = '<a href="http://www.mysite.com" target="_blank">My site</a>';
$patterns = array(
"/<a href=/",
"/target*\=*\'*\_blank*\'*\>/",
"/<*\/a>/"
);
$replacements = array(
"[url=",
"]",
"[/url]"
);
$textarea_content = preg_replace($patterns,$replacements, $textarea_content);
I need to convert the link tag to this structure :
[url='http://www.mysite.com']My site[/url]
The problem is that the output is something like : <a href="" http:="" www.mysite.com''="" target="_blank">My site</a>
What I’m doing wrong ? Thanks for help!
Assuming:
Result:
EDIT According to OP’s comment below:
If want to get back your HTML you just have to do this:
Assuming:
Result: