ALERT in PHP

Solved
snoopy -  
 appkech -
L'équivalent en PHP d'`alert` en JavaScript est `echo` ou `print`, car PHP est un langage côté serveur et ne peut pas afficher une boîte de dialogue comme le fait JavaScript côté client. Pour simuler un `alert` en PHP, vous devez générer un code JavaScript qui sera exécuté dans le navigateur. Par exemple :

```php
echo "<script>alert('Votre message ici');</script>";
```

4 answers

  1. Stéphane
     
    I don't think PHP has a built-in method, but you can dynamically generate JavaScript with PHP:

    <?php if ($variable==0) { echo "<script>alert(\"the variable is null\")</script>"; } ?>
    94
    1. snoopy
       
      Thank you, it works.
      I didn't actually know that you could use <script> in PHP.
      :-)
      0
    2. Shymon Posted messages 150 Status Member 59
       
      Just a quick note: be careful about the differences in usage between PHP and JavaScript. It doesn't make sense to do an "alert()" in PHP since it's a server-side language and not a client-side one.
      In this case, the code above generates JavaScript, and it's the JavaScript (client-side, therefore) that generates the alert...
      I know, I'm just adding my two cents :D But I think it's important to understand the difference if you're programming in both languages!

      Simon
      4
    3. appkech
       
      Thank you
      0