Forum Moderators: coopster

Message Too Old, No Replies

regexp help

need to create a reg exp to match href attributes of a links

         

ngrant

1:09 am on Nov 19, 2008 (gmt 0)

10+ Year Member



I need help building a reg exp to use with preg_replace that will find the href attribute in all a tags and return the url so that I can reference it with the $n format (see the preg_replace manual on php site)

so essential my preg_replace should like like

preg_replace("some regexp","javascript: someFunction('$1');",$myPage)

thanks any help would be mucho appreciated

willis1480

2:45 am on Nov 19, 2008 (gmt 0)

10+ Year Member



why dont you use the javascript solution I gave you?

If you want to use PHP, you will only be able to do a preg_replace if the "a" tag is in a guranteed format. Otherwise you will have to write a more complicated function to match "a" tags and then do a replace.

How are you loading the file to be parsed?

ngrant

4:51 am on Nov 19, 2008 (gmt 0)

10+ Year Member



I am loading the pages through a file called transport.php its from phpfour.com under an article called cross domain ajax. I am writing the parsing myself just using str_ireplace() to change most of the links from relative to absolute, the only ones I am having problems with are the links that are supposed to open in page. I need those links to be replaced with a javascript link calling the url into a function

I.E.

<a href="thispage.asp"> needs to be <a href="javascript: clickLink('thispage.asp')>

but i need to make sure that <a href="http://www.whateverpage.com"> doesn't become <a href="javascript: clickLink('http://www.whateverpage.com')">

I.E. the links that are already absolute before i change them should stay as links where as the relative urls should become a javascript function