Jump to content

str_replace problem *** SOLVED ***


oracle259

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.
Link to comment
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.