Senin, 22 April 2024

Prevent PHP Commented Out

Problem:

when I enter in code like this:

<script language="javascript" type="text/javascript">

function showName() {

   document.getElementById("name").innerHTML = "<p>Hello <?php echo $name; ?>, How are you?</p>";

}

</script>

It prints:

<script language="javascript" type="text/javascript">

function showName() {

   document.getElementById("name").innerHTML = "<p>Hello <!--?php echo $name; ?-->, How are you?</p>";

}

</script>

Solution:

Follow one of this guide to prevent PHP script file to commented out: 

  • You must type PHP script code between <?php tag and ?> tag.
    • Beware of the white space between <? and php.
    • Beware of the white space between ? and >
  • To run PHP scripts file, you have to save the file as a .php file.
    • ensure the file was saved as right file encoding ( Unicode or ANSI encoding for example ).
    • Save the .php file inside the right web server's root directory or DOCUMENT_ROOT folder (\www or \htdocs for example).
  • If the file is being served by Apache, you must enabled the php interpreter to run on html files.
    • to add the .html extension to the php interpreter as below:
      AddType application/x-httpd-php .php .html
    • This line is in the httpd.conf file.
  • You must  to run PHP scripts file from some kind of local server (using Apache through XAMPP for  example) or online hosting server.
    • After you run the local server or upload PHP script file to online hosting server, 
    • view your PHP scripts file through something like http://localhost/mypage.php on the internet browser (Google Chrome for example).
  • Ensure you access the right URL address of your web server's URL PHP scripts file ( http://localhost/mypage.php or http://127.0.0.1/mypage.php for example ).

Bibliography:

https://stackoverflow.com/
https://www.inmotionhosting.com/

Related Post:

Tidak ada komentar:

Posting Komentar

Various Other Posts