newb Posted August 13, 2006 Share Posted August 13, 2006 i was wondering how do i add http:// incase the user forgets to for forms? Quote Link to comment Share on other sites More sharing options...
elhama Posted August 13, 2006 Share Posted August 13, 2006 Well.. you could use a substr() and cut the text and check the first 7 letters, if they aren't http:// you could add itlike 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] Quote Link to comment Share on other sites More sharing options...
newb Posted August 13, 2006 Author Share Posted August 13, 2006 and if they forget www? Quote Link to comment Share on other sites More sharing options...
elhama Posted August 13, 2006 Share Posted August 13, 2006 www wont matter anyways, http://google.com will make just as good as http://www.google.com :) Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 try this ok.[code]<?php$url="www.google.com";if(!eregi("^(http://)",$url)){$rep=str_replace($url,"http://.$url",$url);}?>[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 [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] Quote Link to comment Share on other sites More sharing options...
newb Posted August 13, 2006 Author Share Posted August 13, 2006 k thanks guys Quote Link to comment Share on other sites More sharing options...
newb Posted August 13, 2006 Author Share Posted August 13, 2006 [code=php:0]$url = $_POST['url'];if(!eregi("^(http://www.)",$url) || !eregi("^(http://)",$url)) {$url=str_replace($url,"http://$author_url",$url);}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.