How To Display Alert Message Box In PHP - SkillSugar

Home Tutorials PHP

Contents

  • Example 1
  • Example 2

Share

How to Display Alert Message Box in PHP

John on June 16, 2021

In this tutorial, we will learn two different ways of displaying an alert message box in the users' browser window using PHP.

Example 1

To display the message we can echo a JavaScript alert() function containing a message like this:

<?php // Echo a pop message: echo '<script>alert("This is a message")</script>'; ?>

Example 2

The first example works perfectly well, however, if you would like to display a dynamic message to the user VIA PHP, create a function that accepts a message string then insert it into the JavaScript alert() function like this:

<?php function alertMessage($message) { // Echo a pop message: echo "<script>alert('$message');</script>"; } $m = "This is a message"; // Call the alert function: alertMessage($m); ?>

Related

  •  thumbnail

    How to use the alert() Function in JavaScript

    June 25, 2021
  •  thumbnail

    How to Create New Line in PHP

    December 21, 2020
  •  thumbnail

    How to Center HTML Elements with CSS

    July 09, 2020
  •  thumbnail

    How to use Document onload in JavaScript

    February 10, 2022
  •  thumbnail

    Fade In and Fade Out with jQuery

    January 26, 2021
  •  thumbnail

    How to Use Associative Arrays in PHP

    September 06, 2020

Related Tutorials

 thumbnail

How to use the alert() Function in JavaScript

June 25, 2021  thumbnail

How to Create New Line in PHP

December 21, 2020  thumbnail

How to Center HTML Elements with CSS

July 09, 2020  thumbnail

How to use Document onload in JavaScript

February 10, 2022  thumbnail

Fade In and Fade Out with jQuery

January 26, 2021  thumbnail

How to Use Associative Arrays in PHP

September 06, 2020

Từ khóa » Echo Msgbox Php