I've built a standalone php chat app. Works great with the classic localhost/chat, except I need it to run on an html page I already have. Does it have to be strictly html, the answer is no. The thing is, I know a browser can render html, but it can't render php.
I would just really like to know if there was any way for me to import a php app to a website. Chat app is consisted of 3 files, 2 of them are php which define the form, look and post method, the 3rd one is a log.html, which is used as a dumping place, that's how the app displays the messages,connected users, leaving users, etc.
I tried several different things.
-Tried using iframes
No good. It display raw php code
-Placed everything in www folder in wamp, tried to "require" the files in html page
No good, displays nothing.
There's really no code for me to show off, I've got everything working separately, except I need the php to work from inside my contact.html page.
It sounds like you simply don't understand HTML or PHP. You say that "The thing is, I know a browser can render html, but it can't render php." as if you're doing us a favor, when all it does is confuse us and then you attack us in the comments. A browser can 100% render a PHP file as long as it sends over HTML to the client, and seeing as you believe your PHP app works right now I'm not sure how you've tested it other than through the browser. Maybe you've used PHP from the command line but there'd be no graphical interface, and any HTML code (such as the form you say you've made) would simply be printed into the console where it should be obvious to you that a browser receiving the same thing would render it as HTML.
To prove this to you, just take a look at facebook:
And finally, some demo code to prove my point:
<?php
$thingA = "dogs";
$thingB = "cats";
$finalThing = $thingA . $thingB;
?>
The above code would work perfectly fine, $finalThing would be "dogscats", and your server would take the output of the file (nothing) and send it as HTML.
<?php
$thingA = "dogs";
$thingB = "cats";
$finalThing = $thingA . $thingB;
echo $finalThing;
?>
The above code would do everything the first example did, but the output "dogscats" would be sent to the client as HTML. This would just render the text "dogscats" as if you had an HTML file with just those characters in it (no html tag, body tag, meta tags, or anything else at all).
<?php
$thingA = "dogs";
$thingB = "cats";
$finalThing = $thingA . $thingB;
echo "<!doctype html>";
echo "<html lang='en'>";
echo "<body>";
echo "\t<p> " . $finalThing . "</p>";
echo "</body>";
echo "</html>";
?>
The above would print a valid HTML file (without meta tags or many other useful things but sorry, I don't want to write much more and there's still another example) which should look exactly like the previous example, but with the text displayed on the screen being in a p
tag rather than being raw text just sitting there.
<!doctype html>
<html lang="en">
<head>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<meta charset='UTF-8'/>
<title>Website</title>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
</head>
<body>
<?php
$thingA = "dogs";
$thingB = "cats";
$finalThing = $thingA . $thingB;
echo "\t<p> " . $finalThing . "</p>";
?>
</body>
</html>
And this final example is the best of all, as it shows that a PHP file is simply an HTML file with <?php ?>
tags. These tags are parsed by PHP, evaluated, and anything that needed to get printed in the middle (or wherever) of the HTML file is printed right there. Then the resulting HTML file (including both the raw HTML and the results of your php tags) is sent to the client.