Jump to content


Photo

add http:// incase user forgets


  • Please log in to reply
7 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 13 August 2006 - 04:47 AM

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

#2 elhama

elhama
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 13 August 2006 - 04:53 AM

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?
<?php
$check_text = substr($link, 0, 7);

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

?>


#3 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 13 August 2006 - 05:00 AM

and if they forget www?

#4 elhama

elhama
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 13 August 2006 - 05:02 AM

www wont matter anyways, http://google.com will make just as good as http://www.google.com :)

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 05:05 AM

try this ok.
<?php

$url="www.google.com";

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

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

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 05:27 AM

<?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>";

?>

<?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>";

?>

<?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>";

?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 13 August 2006 - 05:27 AM

k thanks guys

#8 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 13 August 2006 - 05:37 AM

$url = $_POST['url'];
if(!eregi("^(http://www.)",$url) || !eregi("^(http://)",$url)) {

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users