I have a simple code in html (image 1). The code is in the image i uploaded. When i open/run the file in Google chrome or Mozilla it generates wrong code. I tried to 'inspect element in Google Chrome and the code shown is in image 2. It messes up all the code because it generates it like a comment quote.
Why is this happening? Why the quote is transformed into a comment quote?
It looks like the PHP is not being parsed, and the PHP tags are being treated by the browser as comments.
Are you sure that your code is contained within a .php file and that PHP is installed and running on your server?
it seems like you have written php(.php) code in html(.html) file. Confirm your file type
Your server is not configured properly or XAMPP , WAMPP is not installed properly or the remote server has issue or you are running it directly from a file.So:
1-Check Apache if it is parsing PHP.
2-Check if PHP is installed.
3-Check if apache configured ports are free.
4-Ask for support in your contro panel of your hosting providers(if it is on a remote server).
5-Don't double click the PHP file.
6-Check the file extension.
7-Check your .htaccess file(if you have one).
8-Check PHP logs.
This should help you.
For my php I usually use something like this if you only want to out put text.
<?php
echo "<p>Hello world</p>";
?>
Now if you have a variable you will need to do it this way
<?php
echo "<p>Hello".$myname.", welcome to my world.</p>";
?>
Now if you need something in a quote inside the echo statement you should do something like this
<?php
echo "<p>'Hello world'</p>";
?>
Related
I am experimenting with using AWS. To be specific, I am following the tutorial at this link:
https://aws.amazon.com/getting-started/hands-on/build-web-app-s3-lambda-api-gateway-dynamodb/module-three/?e=gs2020&p=build-a-web-app-two
I have tried to add empty PHP tags to the start of the file and renamed the file to index.php instead of the index.HTML of the tutorial. I did a full sequence of refreshing the web app resources and deploying the app on the Amplify console. It did not work. I tried only using the HTML code on index.php and it still did not work. I put back the PHP code, added an echo statement echo "<h1>PHP Code Ran</h1>"; but renamed the file to index.html and it did render. Granted, there was an error in the text output. It also wrote the ending semi-colon and ending quotation, but it worked.
Is there any way for me to use a file named index.php as the home page of a web app using AWS amplify?
A PHP file isn't just an HTML file with a different name: you need to have a server somewhere that's running PHP which will look at the PHP code and run it.
If you're just uploading files to S3, that's not going to happen, the file is just going to be sent straight to the browser, regardless of what you call it and what you put in it.
Putting <?php echo "<h1>PHP Code Ran</h1>"; ?> into a file "worked" only in the sense that when you opened the page in the browser, you saw your browser's best attempt to interpret that as HTML. If you go to "View Source", you'll see that the file is exactly what you uploaded to S3, no PHP has run at all.
If you want to write a PHP application, you need to understand how to run PHP - most likely on an EC2 server, but it could also be in a Fargate container, or something even fancier like bref which lets you run PHP in a Lambda function.
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 3 years ago.
I am trying to do something basic with PHP and HTML first before I get into something big. However, my html page doesn't seem to be processing PHP correctly.
I have the following php code in my html:
<?php echo '<p>Hello World</p>'; ?>
However, the output on the html page is:
'Hello World' on one line
but:
'; ?>
follows hello world
How can I fix this so I get 'hello world'?
PHP doesn't run on browsers, it's executed on the server. To work with PHP on your local machine, you'll want to set up a server, and write in HTML and PHP in a file with a .php extension, not a .html one. The easiest way to get started would be to use xampp as a beginner.
It looks like you are trying to put php code inside a .htm or .html file.
I ran this code as just html and got the following:
Hello World
'; ?>
So, it is properly interpreting the <p></p> tags but everything else is meaningless to it and doesn't know what to do with what comes after it, so it just prints it as is.
To use php, you need to be doing it inside a .php file and you need to be accessing it from a server that recognises .php files. If you are doing this locally, simply opening the file in a browser won't work by default. You will need to setup a local web server that is running a version of PHP. if you don't have much experience, I recommend WAMP because it is easy to set up and run php with.
If you are doing this on a website that is actually hosted (not local), most of them have support by default for PHP, so if you are using a .php file and it isn't working, you should contact the host or read their documentation to figure out how to get their servers to interpret php files.
I create a new HTML file for my project using Dreamweaver and i added a simple php code:
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
so far nothing is appearing while i open the file with google chrome and IE, any thoughts?
PHP has to be executed on the server. Upload it to a web server that supports PHP, or install your own web server locally such as WAMP. You then need to access the file with a URL rather than just opening it. A local URL will look like http://localhost/ or http://127.0.0.1/.
Your file also needs to have the extension .php if it contains PHP code. If you really want to use PHP inside a .html file, your web server will need to be set up specially to handle this.
PHP requires a webserver and an interpreter. Browsers cannot handle PHP on its own.
Look at XAMPP
A good idea to check if your php file is working properly is to load phpinfo function.
This function will show details about your PHP installation:
<?php
phpinfo();
?>
If what you see on the screen is this php code with the entire opening and closing tags (), then you are not running the page with PHP.
<!DOCTYPE HTML>
<html>
<body>
<?php
//printing
echo "<p>Hello, World</p>";
?>
</body>
</html>
This is suppose to be a basic hello world example but when I run it in the browser I get an extra "; ?>
Hello, World
"; ?>
Why is that?
EDIT: Yes the file extension is php
EDIT2: I created the file with Notepadd++. I ran the file by right clicking the file and open with chrome.
EDIT3: Okay so what I gathered is that I can't just run the file locally. I will try through a web server. Thank you for the responses so far!
I believe your problem is that you do not have a local server such as xampp.
I would suggest downloading xampp and then follow the instructions for running a php file.
Make sure you have .php as the file extension
You are probably not running your file through your web server, but you are opening it locally.
Make sure your url is something like http://localhost/myFile.php. And not c:\documents and settings\myName\Desktop\myFile.php.
"I created the file with Notepadd++. I ran the file by right clicking
the file and open with chrome."
You are saying your problem. PHP files are not like HTML files. They must be compiled before served.
For example:
<html><body><?php echo date("Y"); ?><body><html>
will be expected to show the system year. If you try to open it browser does not recognize PHP scripts and treats that function as a text and you see
echo date("Y"); ?>
Why don't you see <?php ? Because after <character, the browser thinks that there is an HTML tag coming.
If you run that PHP file correctly and then look at the source HTML you will see
<html><body>2014<body><html>
You must move the file to web server directory like c:\xampp\www or to c:\wamp\www.
Then run apache server.
After that open a browser window and type localhost/yourfile.php:80
80 could vary in according to your settings (Take a look at httpd.conf file).
I want to use some php to make simple header/footer files for my webpages. I'm just getting started in web design and I am using Coffee Cup HTML Editor.
Problem is I have this line in my index.php file:
?php include(“includes/header.html”);?>
and nothing shows up even though my header.html file has a menu in it.
Do I need to install something on my machine before PHP code will show anything?
Syntax errors
Firstly, your code snippet contains a syntax error. The opening PHP tag should be <?php and not ?php. So your code should look like this:
<?php include('includes/header.html');?>
Install PHP
Secondly, you need to run PHP scripts on a PHP server like XAMPP for the code to actually be executed.
This assumes header.html either contains text or if it is PHP it echo()s its output.