Save searched words in a txt file

Discussion in 'PHP' started by miladk, Mar 17, 2010.

  1. #1
    Hi, i have a normal search function in my site, and i want to save any searched words typed in the search box in a .txt file (like: search.txt).
    each word in a seperate line like this sample.txt

    --------------------------------------------
    new cars
    how make money
    new cars
    etc.
    --------------------------------------------

    This is my search form:
    <form  onsubmit="search(src.value);return false;" id="searchform" method="get">
                    <input type="text"  value=""  id="s" name="src"  />
                    <a onclick="document.getElementById('searchform').submit(); return false;" id="submit-search" href="#"><span>search</span></a>
    
                    <input type="submit" name="submit" style="display: none;" value="search word"/>
                </form>
    Code (markup):

    by which php code can i save the searched words in this txt file?
     
    miladk, Mar 17, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    <form method="get">
    <input type="text" name="src">
    <input type="submit" name="submit" value="Search">
    </form>
    
    <?php
    
    if(isset($_REQUEST['submit']) && !empty($_REQUEST['src'])){
    $fp = fopen('searched.txt',"a");
    fwrite($fp,$_REQUEST['src']."\n");
    }
    
    ?>
    PHP:
     
    danx10, Mar 17, 2010 IP
  3. miladk

    miladk Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thx
    where should i paste this code? the search form is in a .tpl file. and it does not work when pasting in there
    should i create a seperate .php file? if yes how should i point it to the .tpl file?
     
    miladk, Mar 17, 2010 IP
  4. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    are you have search.tpl or similar to parse that search text?
     
    guardian999, Mar 18, 2010 IP