Jump to content

Archived

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

newb

add http:// incase user forgets

Recommended Posts

i was wondering how do i add http:// incase the user forgets to for forms?

Share this post


Link to post
Share on other sites
Well.. you could use a substr() and cut the text and check the first 7 letters, if they aren't http:// you could add it
like this  $something = "http://".$something;


The code would be something like this?
[code=php:0]
<?php
$check_text = substr($link, 0, 7);

if($check_text != "http://")
$link = "http://".$link;

?>
[/code]

Share this post


Link to post
Share on other sites
www wont matter anyways, http://google.com will make just as good as http://www.google.com :)

Share this post


Link to post
Share on other sites
try this ok.
[code]
<?php

$url="www.google.com";

if(!eregi("^(http://)",$url)){

$rep=str_replace($url,"http://.$url",$url);
}

?>
[/code]

Share this post


Link to post
Share on other sites
[code]
<?php

// if the user only puts in google.com replaced with http://www.google.com.

$url="google.com";

if(!eregi("^(http://www.)",$url)){

$replaced=str_replace($url,"http://www.$url",$url);

echo $replaced;

}

echo "<br>";

?>
[/code]

[code]
<?php

// if the user only puts in http://google.com replaced with http://www.google.com.

$url="google.com";

if(!eregi("^(http://)",$url)){

$replaced=str_replace($url,"http://www.$url",$url);

echo $replaced;

}

echo "<br>";

?>
[/code]

[code]
<?php

// if the user only puts in www.google.com replaced with http://www.google.com.

$url="google.com";

if(!eregi("^(http://)",$url)){

$replaced=str_replace($url,"http://www.$url",$url);

echo $replaced;

}

echo "<br>";

?>

[/code]

Share this post


Link to post
Share on other sites
[code=php:0]
$url = $_POST['url'];
if(!eregi("^(http://www.)",$url) || !eregi("^(http://)",$url)) {

$url=str_replace($url,"http://$author_url",$url);
}
[/code]

Share this post


Link to post
Share on other sites

×

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.