1

My code is:

<!DOCTYPE html>
<html>

<head>
We are done <br>
</head>

<body>
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 3;
$y = 4;

echo "<h2>" . $txt1 . "</h2>";
echo "Study PHP at " . $txt2 . "<br>";
echo $x + $y;

?>

</body>
</html>

and output in my browser is:

We are done  
> " . $txt1 . ""; echo "Study PHP at " . $txt2 . ""; echo $x + $y; ?>    

What should I investigate, as something is wrong with my configuration?

Rizier123
  • 58,877
  • 16
  • 101
  • 156
Ayaz
  • 51
  • 1
  • 1
  • 8
  • Do you have a local server running with PHP installed? – Kyle Mar 25 '16 at 04:08
  • Yes WAMP server as per youtube tutorials – Ayaz Mar 25 '16 at 04:16
  • What is the page saved as? `.html` or `.php`? – Kyle Mar 25 '16 at 04:17
  • .php and the browser is chrome – Ayaz Mar 25 '16 at 04:18
  • 1
    does an empty php file with `` work properly? – Kyle Mar 25 '16 at 04:22
  • I have removed all code and put this and in browser i am getting the same – Ayaz Mar 25 '16 at 04:25
  • 1
    Ok if you are't getting back a table with a bunch of info about PHP then that means your server either isn't running or doesn't have PHP installed/configured. I don't know WAMP specifically but I like to use [MAMP](https://www.mamp.info/en/) and it works properly after installing, no configuration needed. – Kyle Mar 25 '16 at 04:28

3 Answers3

1

Your server WAMP OR XAMPP which you are using is not properly configured please make sure that you have properly configured that

varad mayee
  • 619
  • 7
  • 19
0

There is nothing wrong with your code.
That code executes appropriately in a properly configured browser.

Have you verified that php is configured for your browser?

chsbellboy
  • 490
  • 2
  • 15
  • when i put localhost:8085 in browser then it shows me wampserver page with all phptools at the bottom of the page. – Ayaz Mar 25 '16 at 04:37
  • check the http://stackoverflow.com/questions/36214401/text-in-php-echo-wont-show-in-browser – varad mayee Mar 25 '16 at 05:38
  • well that link helps. Thanks for sharing. Problem was Php initial installation not on my system when i try php -v on my system. So i go to php.net and downloaded php-7.0.4-nts-Win32-VC14-x64 on my system. Another odd thing is in youtube videos they just write localhost but i have to write localhost:8085, just localhost doesnt work. – Ayaz Mar 25 '16 at 07:04
0

PHP is a server side scripting language for this you will have to install a web-server software and php so that PHP scripts will be parsed by them.

Browser is capable of only executing Client Side Scripts i.e. HTML, Javascript and not the Server Side Scripts

You may install only PHP and Mysql and use PHP's native server to execute scripts

using command

php -S localhost:<port_no> <Folder Path>

in above command replace Port No. by any port free number(Recommended 4 Digit Port No.) and Folder path by the folder path where your PHP files are saved or simply execute

php -S localhost:<port_no>

By navigating to the same folder in terminal

If you are using windows then you can download XAMPP which is a full stack of Apache, PHP, Mysql and Perl(optional) and execute php Scripts from XAMPP.

Akshay Khale
  • 8,151
  • 8
  • 50
  • 58