fitasoufi
Tokenomics Researcher
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
100 XP
In this tutorial we will create a Simple File Get Contents using PHP. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So Let's do the coding...
Before we get started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.
Lastly, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.
Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
Creating the Main FUnction
This is the main function of the application. This code will fetch the data of the website page. It could fetch any part of the specific page content to display on your page. To do that copy and write inside inside the text editor, then save it as get_data.php.
Note: The given url is the only one working for this code. To make work with other url, just change the url and edit the target content of the page.
⚙ Live Demo
There you have it we successfully created Simple File Get Contents using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!
Download
Before we get started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.
Lastly, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.
Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-widtn, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
- </div>
- </nav>
- <div class="col-md-3"></div>
- <div class="col-md-6 well">
- <h3 class="text-primary">PHP - Simple File Get Contents</h3>
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-3"></div>
- <div class="col-md-6">
- <form method="POST">
- <div class="form-group">
- <label>Target URL:</label>
- <input type="text" class="form-control" name="url"/>
- <br />
- <button class="btn btn-primary form-control" name="save">Get Data</button>
- </div>
- </form>
- <div><?php
include
'get_data.php'
?>
</div>
- </div>
- </div>
- </body>
- </html>
Creating the Main FUnction
This is the main function of the application. This code will fetch the data of the website page. It could fetch any part of the specific page content to display on your page. To do that copy and write inside inside the text editor, then save it as get_data.php.
Note: The given url is the only one working for this code. To make work with other url, just change the url and edit the target content of the page.
- <?php
- if
(
ISSET
(
$_POST
[
'save'
]
)
)
{
- $url
=
$_POST
[
'url'
]
;
- $data_scrapped
=
file_get_contents
(
$url
)
;
- $data
=
explode
(
'<nav id="navigation" role="navigation">'
,
$data_scrapped
)
;
- $end
=
explode
(
'</nav>'
,
$data
[
1
]
)
;
- echo
$end
[
0
]
;
- }
- ?>
⚙ Live Demo
There you have it we successfully created Simple File Get Contents using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!
Download
You must upgrade your account or reply in the thread to view the hidden content.