Regular Expressions - check to make sure string...
Posted: Thu Nov 14, 2002 1:11 pm
I want to check a string, and replace certain characters ONLY IF STRING DOES NOT have ' http:// ' in it.
How can I do this?
How can I do this?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$var_1 = "http://www.hello.com";
$var_2 = "www.hello.com";
function someName($var, $noString, $newChars, $oldChars)
{
if(!strstr($var,$noString))
{
$var = str_replace($newChars,$oldChars,$var);
}
return $var;
}
// Then try it:
$var_1 = someName($var_1,'http://','.com','.net'); // still = http://www.hello.com
$var_2 = someName($var_2,'http://','.com','.net'); // now = http://www.hello.net
?>