PHP with React JS - Combined
By: Luis A. Sierra


Intro:

React is the library for web and native user interfaces. Build user interfaces out of individual pieces called components written in JavaScript.

PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

Getting Started:

This is a Simple HTML Document:

<!DOCTYPE html> <html lang="en"> <meta charset="utf-8"> <title>Title Here</title> <body> <h1>Content Heading</h1> <p>Content paragraph</p> </body> </html>

Output:



Adding React to an HTML Page:

<!DOCTYPE html> <html lang="en"> <title>Test React</title> <script src= "https://unpkg.com/react@16/umd/react.production.min.js"></script> <script src= "https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script> <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script> <body>
<div id="root"></div>
<script type="text/babel"> const name = 'Luis A. Sierra'; function Welcome() { return <h1>Hello {name}</h1>; } ReactDOM.render(<Welcome />, document.getElementById('root')); </script> </body> </html>

Output:








Adding React to an PHP Page:
<?php
//Created by Luis A. Sierra ?>
<!DOCTYPE html> <html lang="en"> <title>Test React</title> <script src= "https://unpkg.com/react@16/umd/react.production.min.js"></script> <script src= "https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script> <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script> <body> <div id="root"></div> <?php $last_name = 'Sierra'; ?> <script type="text/babel"> const name = 'Luis A. <?php echo $last_name; ?>'; function Welcome() { return <h1>Hello {name}</h1>; } ReactDOM.render(<Welcome />, document.getElementById('root')); </script> </body> </html>

Output:








💾 File Repository 


👍 Enjoy!!!

Post a Comment

Previous Post Next Post