Forum Moderators: coopster

Message Too Old, No Replies

Removing Javascript with PHP

while still keeping the link text

         

Timotheos

6:56 am on Apr 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a bunch of links in these pages I inherited that look like this
<a href="javascript:examplefunction('Ref')">link text</a>

How can I strip out just the anchors that have this javascript in it while preserving the link text? I don't use javascript on any other parts of the page. One caveat is most of them are also broken over lines so they sometimes look like this...
<a
href="javascript:examplefunction('Ref')">link text</a>

I've been playing around with some reg ex but I just can't get it to work. Thanks for the help.

Tim

mykel79

10:30 am on Apr 1, 2004 (gmt 0)

10+ Year Member



A good text editor should do the job. For example in EditPlus you could do:
Replace
Find what: <a[\n.]*href="javascript:.*">(.*)</a> 
Replace with: \1

Check the "regular expressions" checkbox and click replace.

Timotheos

5:32 pm on Apr 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Mykel,

That gets me going in the right direction. I'm still having trouble getting the ones broken over lines. I've tried your suggestion plus <a[\r\n.]*href="javascript:.*">(.*)</a> but no luck. If I open it in the hex editor I can see the carriage return (x0D) and the line feed (x0A) and then a space. So what gives? Just one of those simple things to figure out but it seems like it's taking longer then if I just did it manually ;-)

Tim