Jump to content


Photo

Join text


  • Please log in to reply
4 replies to this topic

#1 HAMM3R

HAMM3R
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 13 April 2006 - 06:49 PM

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!

#2 bbaker

bbaker
  • Members
  • PipPipPip
  • Advanced Member
  • 127 posts
  • LocationNY

Posted 13 April 2006 - 07:20 PM

i bet there are other (maybe quicker) ways....but try this

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


#3 HAMM3R

HAMM3R
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 13 April 2006 - 08:04 PM

Ok here is what I have so far...

link.html:
<html>
<body>
<form action="link.php" method="post">
URL <input type="text" name="url"><br/>
<input type="submit" value="send"><br/>
</form>
</body>
</html>

link.php:

<?php

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 = "$url";
$mainsite = "http://domain.com/010110A/http/";

$newsite = $mainsite.'/'.website($website);

echo $newsite; //echos http://domain.com/blah/LINK.com

?>

No luck though. I does to go link.php but it echos $newsite as 'http://domain.com/010110A/http//'. Any ideas?

#4 bbaker

bbaker
  • Members
  • PipPipPip
  • Advanced Member
  • 127 posts
  • LocationNY

Posted 13 April 2006 - 08:22 PM

$website = [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]"[!--colorc--][/span][!--/colorc--]$url[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]"[!--colorc--][/span][!--/colorc--]; <--- remove the [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]"[!--colorc--][/span][!--/colorc--]'s
$mainsite = "http://domain.com/010110A/http[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]/[!--colorc--][/span][!--/colorc--]"; <--- remove the [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]/[!--colorc--][/span][!--/colorc--]

Is the varialbe $url 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:

<?php

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 = $_REQUEST['url'];
$mainsite = "http://domain.com/010110A/http";

$newsite = $mainsite.'/'.website($website);

echo $newsite; //echos http://domain.com/blah/LINK.com

?>


#5 HAMM3R

HAMM3R
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 13 April 2006 - 10:21 PM

It worked like a charm, thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users