HAMM3R Posted April 13, 2006 Share Posted April 13, 2006 I have a form. A user inputs a URL into that form. I need a php script to process that URL in the following ways...1. If the URL has a http:// in front of it, remove it.2. Add the URL (without http://) to [a href=\"http://domain.com/blah/LINK.com\" target=\"_blank\"]http://domain.com/blah/LINK.com[/a]And i should be able to get it from there. So all I need is the removal of http:// and the joining to the base url. Im sure there is a simple php function to do this but I have no clue where to start. Can someone possibly provide me with a small snippet to get me started?Thanks! Quote Link to comment Share on other sites More sharing options...
bbaker Posted April 13, 2006 Share Posted April 13, 2006 i bet there are other (maybe quicker) ways....but try this[code]function website($website) { $website = str_replace("http://www.","",$website); //if user enters http://www.LINK.com $website = str_replace("http://","",$website); //if user enters http://LINK.com $website = str_replace("www.","",$website); //if user enters www.LINK.com return $website;}$website = "http://www.LINK.com";$mainsite = "http://domain.com/blah";$newsite = $mainsite.'/'.website($website);echo $newsite; //echos http://domain.com/blah/LINK.com[/code] Quote Link to comment Share on other sites More sharing options...
HAMM3R Posted April 13, 2006 Author Share Posted April 13, 2006 Ok here is what I have so far...link.html:[code]<html><body><form action="link.php" method="post">URL <input type="text" name="url"><br/><input type="submit" value="send"><br/></form></body></html>[/code]link.php:[code]<?phpfunction website($website) { $website = str_replace("http://www.","",$website); //if user enters http://www.LINK.com $website = str_replace("http://","",$website); //if user enters http://LINK.com $website = str_replace("www.","",$website); //if user enters www.LINK.com return $website;}$website = "$url";$mainsite = "http://domain.com/010110A/http/";$newsite = $mainsite.'/'.website($website);echo $newsite; //echos http://domain.com/blah/LINK.com?>[/code]No luck though. I does to go link.php but it echos $newsite as 'http://domain.com/010110A/http//'. Any ideas? Quote Link to comment Share on other sites More sharing options...
bbaker Posted April 13, 2006 Share Posted April 13, 2006 $website = [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--][b]"[/b][!--colorc--][/span][!--/colorc--]$url[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--][b]"[/b][!--colorc--][/span][!--/colorc--]; <--- remove the [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--][b]"[/b][!--colorc--][/span][!--/colorc--]'s$mainsite = "http://domain.com/010110A/http[b][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]/[!--colorc--][/span][!--/colorc--][/b]"; <--- remove the [b][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]/[!--colorc--][/span][!--/colorc--][/b]Is the varialbe [i]$url[/i] define anywhere? You have to pull that info from the form or you could just replace $website = "$url"; with$website = $_REQUEST['url'];so you're link.php would be this:[code]<?phpfunction website($website) { $website = str_replace("http://www.","",$website); //if user enters http://www.LINK.com $website = str_replace("http://","",$website); //if user enters http://LINK.com $website = str_replace("www.","",$website); //if user enters www.LINK.com return $website;}$website = $_REQUEST['url'];$mainsite = "http://domain.com/010110A/http";$newsite = $mainsite.'/'.website($website);echo $newsite; //echos http://domain.com/blah/LINK.com?>[/code] Quote Link to comment Share on other sites More sharing options...
HAMM3R Posted April 13, 2006 Author Share Posted April 13, 2006 It worked like a charm, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.