+ 1
We can print any statement by using p tag why we need to write echo(php) in our code?
5 Respostas
+ 2
The <p> tag is part of HTML, not PHP. Echo is a way for you to echo back a message from the server end. The <p> tag is part of your HTML that you receive and is on your local end as part of the "end result" of loading the page. The <p> tag is going to help browsers present paragraph data in their particular ways, and also helps with the actual structure of your HTML code. With the echo command, you can literally echo whatever you want, including HTML code. So maybe something happens from the server end, and depending upon the result, you'll want to embed some HTML back into the page when it loads. You can't do that with HTML tags.
EXAMPLE:
Lets say you have a user that just logged in. You could have something like:
<?php
if(isset($_SESSION['username']) {
$activeUser = $_SESSION['username'];
echo '<p>Welcome, $activeUser</p>';
}
?>
^When the loads and the server runs that, it's going to check if there is a session variable for 'username' which would potentially indicate that a user is logged in. If they're logged in, it'll add that HTML code to the document and replace the PHP variable with the username stored in the session variable.
Make sense?
+ 2
yeah and thank you
+ 1
If you can, try to reword your question for me. I'm more than happy to help, but I'm not understanding your question.
As for what PHP is, it's a server-side language for your websites. It'll allow you to handle things on the server that you wouldn't be able to otherwise. For example, you can use your PHP to access and do as you wish with your database, which could be useful if you're creating an account/login system, blog, forum, etc... Pretty much anything you need to do from a server-side instead of client-side, you'll use your PHP for (or any other server-side language, such as NodeJS).
+ 1
Means php is like programming language like c,c++ etc where we use its feature like operator,loops etc in Html ??
+ 1
Yea, it's a programming language, so you can use all of your logic and such to handle things from the server end. I notice you finished the course for it today, so congrats on that. It's really fun to play around with and you can do all sorts of things with it, especially when you combine your knowledge of JavaScript/HTML/CSS/SQL with it. (learn those if you haven't) I'd take some time to learn jQuery after your learn JS also. It enhances JS greatly and gives it better syntax in the process.