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
https://forums.phpfreaks.com/topic/7336-join-text/
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
https://forums.phpfreaks.com/topic/7336-join-text/#findComment-26706
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
https://forums.phpfreaks.com/topic/7336-join-text/#findComment-26721
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
https://forums.phpfreaks.com/topic/7336-join-text/#findComment-26727
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.