Jump to content

Archived

This topic is now archived and is closed to further replies.

oracle259

str_replace problem *** SOLVED ***

Recommended Posts

I really hope u guys can help me on this one  ???.

[code]
$match = str_replace("*", '', $string);
$match = strlen($match);

if ($match == 0) {
return False;
} else {
return True;
}
[/code]

From the code you can see the problem clearly that if no *** are present in the $string,  $match = strlen($match) also returns 0 which does not work for me. How do i change this code to make sure that $match = 0 only when *** are present in the $string and replaced.

Thanks.

Share this post


Link to post
Share on other sites
Try putting speechmarks around the 0

ie

[code=php:0]$match = str_replace("*", '', $string);
$match = strlen($match);

if ($match == "0") {
return False;
} else {
return True;
}
[/code]

Share this post


Link to post
Share on other sites
Actually, after reading this again i think I have the wrong end of the stick

One way to do it would to be to count the string length before and after the string replace, and have the "false" returned only if there is a difference in those two numbers and the second one comes back as 0

eg
[code=php:0]
$count1 = strlen($string);
$match = str_replace("*", '', $string);
$match = strlen($match);

if ($match == 0 AND ($count1 != $match)) {
return False;
} else {
return True;
}[/code]

Is that more what you were after?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.