开发者

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';
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜