SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Line Break In Alert Box Based On Php Variable

    How do I get the line break to work in an alert box based on data from this php variable?
    PHP Code:
    <?php
    $myPhpVar 
    '"Hello again! This is how we" . "\n" . "add line breaks to an alert box!"';
    echo 
    '<script type="text/javascript">';
    echo 
    'alert(' $myPhpVar ');';
    echo 
    '</script>';
    ?>

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,332
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Have you tried this?
    Code:
    <?php
    $myPhpVar = '"Hello again! This is how we" . "\n" . "add line breaks to an alert box!"';
    ?>
    <script type="text/javascript">
      alert("<?php echo $myPhpVar; ?>");
    </script>
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Why are you generating alerts from PHP when the only purpose for alerts in the 21st Century is for debuggung JavaScript (which is why some languages include an option in alerts for either turning off further alerts or disabling Javascript for the page).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'll use the alerts to monitor incremental changes in mysql tables.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •