开发者

How can I make this PHP else statement work?

开发者 https://www.devze.com 2023-04-02 15:34 出处:网络
<?php if (!empty($_GET[\'type\'])) { echo 开发者_运维问答str_replace(\" \", \"\", strtolower(htmlspecialchars($_GET[\'type\'])));
<?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

精彩评论

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