How to embed php script in javascript?

前端 未结 6 888
余生分开走
余生分开走 2020-12-11 12:26

I want to know if I can include php scripts in javascript[1] the same way it can be done in html[2]

server.php:


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 12:40

    I tested this solution on PHP 5.5.
    1. Create a file called myScript.php.

    // myScrpt.php content:

    
    
    1. Create a file called test.php.

    // test.php content:

    
    
    
    Include php Script
    
    
    
    
    

    The result is:

    1. When you open test.php in a browser, you will get:

    My full name is Jason Kent.

提交回复
热议问题