Hi I want to verify if a string has "http://" or not so i will add to the link work rigth retrieved from the database . because it do not work when is not enrtered [url]http://[/url] on the db entry thank“sn advance
If you're just checking if the string has it, you can use something like:
if ( !stristr($string, "http://") ) { $string = "http://{$string}"; }
Pretty simple, but, doesn't really validate much.
I use this validation a lot that you are asking about. The below does the correction the way you want it to and you do not have to prompt the user to correct.
$variable = "ronfrederick.com"; if (ereg("http://",$variable)) { $new_var = $variable; } else { $new_var = "http://$variable"; } echo $new_var;
the 1st reply, which does not use regular expressions ("ereg") is faster-- thought we're talking about milliseconds here, so, it may not matter. fwiw.
Great both answers help me a lot
Best regards !!!