I am not good at Regular Expression,. I am trying the following: Change the line1 to line2: Line1: "<a href='sub1/mypage.php'>MyPage</a>" line2: "<a href='http://mydomain.com/sub1/mypage.php'>MyPage</a>" Of couse, if line2 stay the same when line 1 is: "<a href='http://something.com/sub1/mypage.php'>MyPage</a>" The point is: line2 shouldn't change if there is http:// or ftp:// or anything else! Please help if you have clue!
if (strpos("$url", "://") !== false) { // the url contains a :// } else { str_replace("sub1","http://yourdomain.com/sub1",$url); } PHP: Maybe start with something like this.
Further more, my problem relates to redirect URL, for example, with absolute URL: $url="http://bh2.host.sk/"; // Or just any ABSOLUTE URL $redirect="http://mydomain.com/mycript.php"; $link1="This is the link <a href=\"http://bh2.host.sk/sub1/PHP.doc\">The document </a>"; echo "\n<br>1.1 ".eregi_replace("href=\"([a-z]+://.+)\"","href=\"$redirect?url=\\1\"",$link1); PHP: But I meet problem with RELATIVE URL, for example if link2 $link1="This is the link <a href=\"sub1/PHP.doc\">The document </a>"; $domain="http://bh2.host.sk" PHP: I need to have a result something like: http://mydomain.com/myscript.php?url=http://bh2.host.sk/sub1/PHP.doc Code (markup):