Reputation: 83
When running this PHP code:
// test value
$value = "123456-7890";
// remove blank spaces and explode
$value = str_replace(' ', '', $value);
$value = explode('-', $value);
// check number of digits depending on format
if ((count($value) == 1 && strlen($value[0]) != 10) || (strlen($value[0]) != 6 || strlen($value[1]) != 4))
{
echo "wrong number of digits!";
}
I get the following error:
PHP Fatal error: Call to undefined function () in /Users/Rikard/Desktop/test.php on line 10
As far as I can tell the problem arises in this part: strlen($value[0]) != 10
but I cannot see why it appears, any thoughts?
Upvotes: 0
Views: 248
Reputation: 14616
You see this:
if ((count($value) == 1 && strlen($value[0]) != 10) || (strlen($value[0]) != 6 || strlen($value[1]) != 4))
PHP sees this (•
means non-breaking space):
if ((count($value) == 1 && strlen($value[0]) != 10) ||•(strlen($value[0]) != 6 || strlen($value[1]) != 4))
It always happens to me when I innocently try to copy some code from Mac/Safari. BTW, I tried to "edit" your question, and copied code from there for further examination.
PHP interprets the non-breaking space as a valid function name, and tries to execute it:
•(strlen($value[0])
Upvotes: 6