Hi!
I use a ereg_replace to convert URLs in a press release into working links.
I use the following code:
echo ereg_replace("http://([^ ]*)", "<a href=\"http://\1\" target=\"_blank\">http://\1</a>", htmlentities($pm[text]));
That works!
Now it would be interesting to set the target of the <a> tag to "parent" if the URL points to a page within the same website and to set it to "blank" if the link goes somewhere else. I changed my code to:
echo ereg_replace("http://([^ ]*)", "<a href=\"http://\1\" target=\"".(strpos("www.pefc.", \1)?"parent":"blank")."\">http://\1</a>", htmlentities($faq[antwort]));
That doesn't work (which was easy to guess)
\1 contains the URL, however I didn't manage to use this in the strpos() function to detect the website's URL (which is www.pefc.).
Do the patterns found get written somewhere else (maybe into a real variable), which would be easy to access in strpos().
Thanks,
Matthias