Hello! Need regular expression to replace all HREFs in A tags with # - all I found on php.net was eregi_replace('<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>].*>','<a href="#">', $string); which doesn't work. Are there any ready-to-go solutions? Thanks =)
Try this, $var = preg_replace("/\s([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]* \@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})([\s|\.|\,])/i", " <a href=\"$1\">", $var); PHP:
Exactly opposite thing needed: from <A href="link_here" class="someClass" target="_someTarget"> Code (markup): I need to make <A href="#" class="someClass" target="_someTarget"> Code (markup): in full page's code (in simple words I need PHProxy to replace all clickable A tags into # anchors)
Thanks but this expression going to rewrite Link/Style tags also (<link rel="style" href="some_href") - need to replace only A tags. Getting errors (like everything replaced with #) then trying to use something like /<a*href=['\"][^'\"]*['\"]/i/
use /<a[^>]*=['"][^'"]*['"]/i if you want to match only a tags href. (Note: the escape char \ is for the php string)
Any ideas how does it looks like in working form? Because $_response_body = eregi_replace('/<a[^>]*=[\'"][^\'"]*[\'"]/i','<a href="#"',$_response_body); does nothing.
Try this regexp: $_response_body = preg_replace('/<a(.*)href=\"(.*?)\"(.*)>/', '<a$1href="#"$3>', $_response_body) PHP: I tested it.. it works.
Problem with that one is that it will mess you up if you come across something like this: <a name='whatever'>blahblahblah <a href='click here'> All the necessary pieces of the puzzle have been posted here, but strangely never together at once. What you want is closer to this: $new = preg_replace('/(<a[^>]+href=")[^"]+/i', '\1#', $old); PHP: