PHP output JavaScript script with PHP parameter, function argument string with variable

Source: Internet
Author: User

1, in PHP, sometimes we need to echo out the JS script, and this script with PHP settings variables

How to output, a bit fastidious, write down to spare. Here's how:

(1) The first method

<?php

$_HG = ' Hong ';

Echo ' <script type= "Text/javascript" >alert ("My name is '. $_hg. '"); History.back ();</script> ';

?>

(2) The second method, the implementation of changing single quotation marks, the quotation of double quotes <?php $_hg = ' Hong '; echo "<script type= ' text/javascript ' >alert (' My name is '. $_hg. '); </script> ";? >

2. We encapsulate the above PHP code into a function, passing in arguments with strings

$_hg= ' Hong ';

function _alert_look ($_hh) {

echo "<script type= ' text/javascript ' >alert ('". $_hh. "); </script> ";

}

We call the function to do this:

_alert_look ("My Name is". $_hg. " Complete! ");

PHP output JavaScript script with PHP parameter, function argument string with variable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.