Why can't I use strpos to find a # in a string?

This code works good elsewhere on my website, but it always fails if $formBusinessName has a # in it. Any ideas?

Thanks!

if (strpos($formBusinessName,"#") !== false) {
$error = "Yes";
$errorMessage .= "<li>Your business name can not contain a distributor number.</li>";
}

Unless I’ve missed something it seems to work for me!
In order to test it I added some code:

if (strpos($formBusinessName,"#") !== false) {
  $error = "Yes";
  $errorMessage .= "<li>Your business name can not contain a distributor number.</li>";
}
else {
  $error = "No";
  $errorMessage .= "<li>Your business name is okay.</li>";
}
echo $error, "\n";
echo $errorMessage;

and tried it with $formBusinessName = “abc123”; and $formBusinessName = “abc#123”;

Did you try
$formBusinessName = undefined;

Oooops, I thought I was editing code in Test, but I was actually in Development at the time. I’ll know for next time.

Thanks.

No, OP said it wasn’t working with #, so I simply tried with and without #. I tend to use strstr().

I just tried several variations and it worked fine for me.

I notice $errorMessage appends and $formBusinessName suggests it’s a $_POST value that has been validated / sanitized - i.e. the code involved has not been posted.

busboy, if you echo or var_dump $formBusinessName before the if test what does it look like?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.