texelate Posted November 21, 2006 Share Posted November 21, 2006 Can someone help me with the regular expressions to remove all the hyperlinks from some HTML but leave the text for thelink in there?Eg:$html = '<div>This is <a href="link.html">Link 1</a> and <a href="link.html" target="_blank">Link 2</a> etc</div>';. . . would become . . .'<div>This is Link 1 and Link 2etc</div>'Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/27952-remove-all-hyperlinks-from-html/ Share on other sites More sharing options...
Nicklas Posted November 21, 2006 Share Posted November 21, 2006 [code=php:0]echo preg_replace('/<a href[^<>]+>|<\/a>/s', '', $html);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27952-remove-all-hyperlinks-from-html/#findComment-127877 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.