hi all, i am writing a guestbook with the option to enter a website. what i am searching for but not found yet is a possibility to check if this url entered by the user contains the http:// tag at the beginning to avoid opening the url in the current directory.
thanks in advance!
if(substr($strURL,0,7)=='http://') { //exists } else { //does not exist }
or
http://php.net/strstr
$string = "PHP"; $container = "I love writing PHP code."; if(strstr($container,$string)) { echo "found it."; } else { echo "not found."; }
Before sending to database or text file, run an eregi function:
$website = ereg_replace("http://", "", $website );
If you need to set the link back up later, just do something like:
printf("<a href='http://$website'>$linkname</a>");
Hope that helps.
thanks, both works fine 🙂