+ 3

How to use PHP ?

I just finished the PHP Tutorial but I still can't actually use it in my Testing Website, so I need to know should I write the PHP code inside of the HTML file, or the JS file, or in a file of it's on ? if it's in a file alone how to link it with the HTML file?

12th Feb 2018, 9:17 PM
‏‪Master Z‬‏
‏‪Master Z‬‏ - avatar
6 Answers
+ 2
You write it into php file. HTML file doesn't support php but php file supports php, html, css and javascript. index.php <?php /* Your php code */ ?> <html> <head> </head> <body> </body> </html> There you go. Start with that
12th Feb 2018, 9:25 PM
Toni Isotalo
Toni Isotalo - avatar
+ 3
just put it in your html file but be sure to open it correctly or you will mess up your code
12th Feb 2018, 9:19 PM
Julian
Julian - avatar
+ 2
Here's example <ul class="menu menu-right"> <?php if($login == false) { ?> <li><a href="/login">Login</a></li> <li><a href="/register">Register</a></li> <?php } else if($login == true) { ?> <li><a href="/profile">Profile</a></li> <li><a href="?logout">Logout</a></li> <?php } ?> </ul>
12th Feb 2018, 9:30 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
Thanks Toni That was very helpful 👍
12th Feb 2018, 9:43 PM
‏‪Master Z‬‏
‏‪Master Z‬‏ - avatar
0
Should I write it in a specific Tag or anywhere ?
12th Feb 2018, 9:22 PM
‏‪Master Z‬‏
‏‪Master Z‬‏ - avatar
0
No. inside <?php ?> always. No html tags needed. You can include it anywhere in your document.
12th Feb 2018, 9:29 PM
Toni Isotalo
Toni Isotalo - avatar