Jump to content

Join text


HAMM3R

Recommended Posts

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!
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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]<?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

?>[/code]

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

$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]<?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

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.