0

Basically i have the search script working well, but i need to replace the $input with $inputused if word is found.
I have tried str_replace() with no luck any ideas?
Thank you

<html>
<body>
<form name="form" method="post">

<br><input type="text" id="search" name="search_box" style="background:#000006; color: #FF0000" />


                   <br><input type="submit" name="submit" value="Search for Key" />

            </form>


    </body>
</html>





<?php
$myurl = "./testFile.txt";
$input = $_POST['search_box'];
$inputused = $input . "-" . "USED";

if(isset($_POST['submit'])){
if (!strlen(trim($_POST['search_box']))){
echo "You must enter a key.";
} else {

if(isset($_POST['submit'])){
$file = file_get_contents($myurl);
$split = explode("\n", $file);

if(in_array($input, $split))
{
    echo "It's here!";
} else
{
echo "NOT FOUND";
}
}
}
}
?>
1
Contributor
1
Reply
18
Views
4 Years
Discussion Span
Last Post by Tko_1
0

I got it. seems to works okay but if theres a better way you know of..

<html>
<body>
<form name="form" method="post">

<br><input type="text" id="search" name="search_box" style="background:#000006; color: #FF0000" />


                   <br><input type="submit" name="submit" value="Search for Key" />

            </form>


    </body>
</html>





<?php
$myurl = "testFile.txt";
$input = $_POST['search_box'];
$inputused = $input . "-" . "USED";
$lines = file($myurl);
$cookie_file_path=$myurl;


if(isset($_POST['submit'])){
if (!strlen(trim($_POST['search_box']))){
echo "You must enter a key.";
} else {

if(isset($_POST['submit'])){
$file = file_get_contents($myurl);
$split = explode("\n", $file);

if(in_array($input, $split))
{
    echo "It's here!";
$contents = file_get_contents($cookie_file_path);
file_put_contents($cookie_file_path, str_replace($input, $inputused, $contents));
} else
{
echo "NOT FOUND";
}
}
}
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.