I want to check a string, and replace certain characters ONLY IF STRING DOES NOT have ' http:// ' in it.
How can I do this?
Regular Expressions - check to make sure string...
Moderator: General Moderators
-
superwormy
- Forum Commoner
- Posts: 67
- Joined: Fri Oct 04, 2002 9:25 am
- Location: CT
try this:
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
?>