+ 4
Please, help with SEARCHBAR: insert keyword to input and get results in google. How can I save the result web page to xml, csv?
https://www.sololearn.com/Discuss/768079/do-you-know-any-simple-way-how-to-transfer-html-script-to-xml-csv-in-terms-of-php Please, look at the code below.
3 odpowiedzi
+ 3
Please, is this the right way to how to save files in different formats? Thank You for Your ideas!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Searchbar</title>
<link rel="stylesheet" href="style.css"
<body>
<header>
<h1>Welcome to searchbar</h1>
</header>
<section>
<form action="" method="POST">
Insert the keyword:
<input type="text" name="keyword"><br><br>
<input type="submit" value="Submit">
<input type="submit" name="saveitasxml" value="Save it as XML">
</form>
</section>
</body>
</html>
<?php
if (isset($_POST['keyword'])) {
$keyword = htmlentities($_POST['keyword']);
if (!empty($keyword)) {
$url = "http://www.google.com/search?q=";
$openingFile = file_get_contents($url.$keyword);
echo $openingFile;
} else {
echo 'Please type a keyword.';
}
}
if (isset($_POST['saveitasxml'])) {
file_put_contents("filename.xml", $openingFile);
}
?>
+ 2
This ECHO I use for add the keyword to google search url: echo ("<a href='http://www.google.com/search?q=".$searchbox->__toString()."'>"."<input type=\"submit\" value=\"Find\">"."</a>");
+ 2
Once more the script:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Searchbox</title>
</head>
<body>
<h1>Searchbar</h1>
<h2>Insert the keyword</h2>
<section>
<form method="POST">
Keyword:<br />
<input name="word" type="text" /><br /><br />
<input type="submit" value="Insert"/>
</form>
<?php
require_once('classes/Searchbox.php');
if ($_POST) {
$searchbox = new Searchbox();
$searchbox->word = $_POST['word'];
echo("<h2>Results</h2>");
echo ("<a href='http://www.google.com/search?q=".$searchbox->__toString()."'>"."<input type=\"submit\" value=\"Find out\">"."</a>");
}
?>
</section>
</body>
</html>