How can I make this PHP else statement work?
<?php if (!empty($_GET['type']))
{
echo 开发者_运维问答str_replace(" ", "", strtolower(htmlspecialchars($_GET['type'])));
} ?>
I want this to return 'helloworld' when the type variable is 'Hello World' and this works perfectly. However, I'm trying to add an else statement, which, for example, returns 'invalid' if the input is empty. How can I do this?
you mean?
<?php
if(!empty($_GET['type'])) {
echo(str_replace (" ", "", strtolower(htmlspecialchars($_GET['type']))));
} else {
echo('invalid');
}
?>
First of all format your code.
Second, here you go.
<?php
if(!empty($_GET['type'])) {
echo(str_replace (" ", "", strtolower(htmlspecialchars($_GET['type']))));
}
else {
echo('invalid');
}
?>
<?php
if(isset($_GET['type']) && !empty($_GET['type']))
{
echo(str_replace (" ", "", strtolower(htmlspecialchars($_GET['type']))));
}
else
{
echo 'invalid';
}
?>
精彩评论