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? Link to comment https://forums.phpfreaks.com/topic/17384-add-http-incase-user-forgets/ 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] Link to comment https://forums.phpfreaks.com/topic/17384-add-http-incase-user-forgets/#findComment-73951 Share on other sites More sharing options...
newb Posted August 13, 2006 Author Share Posted August 13, 2006 and if they forget www? Link to comment https://forums.phpfreaks.com/topic/17384-add-http-incase-user-forgets/#findComment-73952 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 :) Link to comment https://forums.phpfreaks.com/topic/17384-add-http-incase-user-forgets/#findComment-73954 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] Link to comment https://forums.phpfreaks.com/topic/17384-add-http-incase-user-forgets/#findComment-73955 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] Link to comment https://forums.phpfreaks.com/topic/17384-add-http-incase-user-forgets/#findComment-73960 Share on other sites More sharing options...
newb Posted August 13, 2006 Author Share Posted August 13, 2006 k thanks guys Link to comment https://forums.phpfreaks.com/topic/17384-add-http-incase-user-forgets/#findComment-73961 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] Link to comment https://forums.phpfreaks.com/topic/17384-add-http-incase-user-forgets/#findComment-73964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.