/    Sign up×
Community /Pin to ProfileBookmark

Why I See Blank Page And Not echoed FALSE ?

Folks,

Why I see blank page and not echoed “FALSE” ?

[code]
<?php

$input = 123;

function FILTER_VALIDATE_STRING($data)
{
if(!is_string($data))
{
$value = FALSE;
}
else
{
$value = TRUE;
}
return $value;
}

echo FILTER_VALIDATE_STRING($input);
[/code]

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmOct 25.2021 — You should see a 1 for the TRUE value, but a FALSE doesn't display anything. And in your example you are getting back a false reading since your $value is not a string.
Copy linkTweet thisAlerts:
@NogDogOct 25.2021 — e.g....
[code=php]
echo FILTER_VALIDATE_STRING($input) ? 'True' : 'False';
[/code]

(See [u][Ternary Operator](https://www.php.net/ternary#language.operators.comparison.ternary)[/u].)
Copy linkTweet thisAlerts:
@developer_webauthorOct 28.2021 — @NogDog#1638566

Thanks for correcting my code.
Copy linkTweet thisAlerts:
@developer_webauthorOct 28.2021 — @ginerjm#1638565

Thanks for telling me this. Saved me countless of time to figure that out.
Copy linkTweet thisAlerts:
@developer_webauthorOct 28.2021 — @ginerjm#1638565

So, let's say the $value is FALSE which shows nothing. How do I read that the $value is FALSE, apart from using the TERNARY like NogDog did ?

I mean, apart from coding it this following way, how would you code it ?
<i>
</i>&lt;?php

$input = 123;

function FILTER_VALIDATE_STRING1($data)
{
if(is_string($data))
{
$value = TRUE;
}
else
{
$value = FALSE;
}
GLOBAL $value;
return $value;
}

echo FILTER_VALIDATE_STRING1($input);
if($value==1)
{
echo 'TRUE';
}
else
{
echo 'FALSE';
}

?&gt;


Not much good reading BOOLEAN. I'd appreciate if you can show me a code sample.

Thanks
Copy linkTweet thisAlerts:
@ginerjmOct 28.2021 — A sample of WHAT? What the h.... are you trying to do here?

Booleans don't display well at all. So what's the point of this meaningless exercise?
Copy linkTweet thisAlerts:
@NogDogOct 28.2021 — If you're just testing code, you can use var_export() or var_dump()to see the type and value, but that's generally not suitable for normal output to normal users.
<i>
</i> $foo = false;
echo "The value of foo is: "; var_export($foo);
// The value of foo is: false

echo "The value of foo is: "; var_dump($foo);
// The value of foo is: bool(false)
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...