PHP - 在页面顶部发布警报

Is it possible to display an error sourced from PHP in a bootstrap alert at a certain part of HTML? Their are alerts within the example.php files which I would like to show on the main page. I tried creating a function in PHP were i wanted the alert to go like so...

Main File function

function postAlert($good, $text) {
    $type = 'danger';
    if($good){
        $type = 'success';
    }
    echo '<div class="alert alert-'.$type.' alert-dismissable"> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong> '. $text.' </strong></div>';
  }

Example File that was included

...
postAlert(true,'This is an error example');
...

I tried calling this function in one of the example php files but nothing appeared to happen and no errors occurred. Is there something I'm doing wrong or is there a better way of doing this?

<?php include 'navbar.php'; ?>

<!-- Alert goes here -->

<div class="container">
  <div class="row">
    <?php include 'example1.php' ?>
    <?php include 'example2.php' ?>
    <?php include 'example3.php' ?>
  </div>
</div>

In php . is used for concatenation.While you are using + in alert. change your function as below

function postAlert($good, $text) {
    $type = 'danger';
    if($good){
        $type = 'success';
    }
    echo '<div class="alert alert-'.$type.' alert-dismissable"> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong> ' . $text . ' </strong></div>';
  }