Joseph
Joseph

Reputation: 41

Text in PHP echo won't show in browser

I use OS win10, xampp ( xampp manager already run and apache too) localhost and phpadmin run well. but when I write coding phpinfo.php like this coding

<?php 
phpinfo();
?php

in chrome will show same like that coding. But if I add HTML format then in chrome will blank or not show any it happens with coding

<HTML><BODY> <?php echo "Hello World!" ?> </BODY></HTML>

I already put there C:\xampp\htdocs but still don't show any. if I write code without html

<?php Echo " Hello World ! " ?> 

then chrome show all script php code in browser.

is anyone can help me ? thanks a lot

Upvotes: 4

Views: 15980

Answers (1)

Ali Zia
Ali Zia

Reputation: 3875

Sounds like there is something wrong with your configuration, here's a few things you can check:

  1. Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run php -v from a command line and see if returns version information or any errors.

  2. Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like LoadModule php5_module "c:/php/php5apache2_2.dll" in the file. Search for LoadModule php, and make sure that there is no comment (;) in front of it.

  3. Make sure that the http.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.

  4. Make sure your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.

  5. Make sure you are not using short tags in the PHP file (<?), these are deprecated not enabled on all servers by default. Use <?php instead (or enable short tags in your php.ini whith short_open_tag=On if you have code that relies on them).

  6. Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

And lastly check the PHP manual for further setup tips.

Source: Here

Upvotes: 2

Related Questions