Jump to content

add http:// incase user forgets


newb

Recommended Posts

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

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.