URL Replacement

Hi.

I am trying to work out how to replace every occurence of a URL that is surrounded with and replace that with another url?

I know I need preg_match (I think) but I cant get my head arround it.

Cheers
Chris

I think something went wrong with you post … how about you show us a start string, and then show us how that should end up (ie with a link in it)?

Hi.

Sorry it was all a bit rushed.

I currently have this


$articleContent =preg_replace('/<a href="([^<]*)">([^<]*)<\\/a>/', '<a href="http://www.example.com/">Sign Up For Access</a>', $resource[1])

which replaces all occurences of links within a page and changes them for the other link - This works reasonably well EXCEPT its indiscriminate, I want to be able to choose which links are replaced. I thought about tagging the links I want replaced with and only then replacing those - however I am not sure how to go about and identify my tags and then replace the url contained within.

Hope this is clearer

Thanks
Chris

If you can modify the source, why aren’t you?

Because I need to replace the links depending on whether they are logged in

If they are logged in I want to display the actual link and if they are not logged in I want to display another link.

Cheers
Chris

Okay. My point was, why not just use a placeholder if you can modify the source?


<a href="WHATEVER_URL">I go somewhere</a>
<?php
$url = 'http://www.example.org/';
if(LOGGED_IN){
	$url = 'https://members.example.org/';
}
$html = str_replace('WHATEVER_URL', $url, $html);

Ah I see… and that makes perfect sense

However I have potentialy many links to take care of in this way and I can see the placeholder route getting very messy very quickly

I think what I am asking is - what is the reg_ex expression to match everything between

Thanks
Chris