Sending multiple values from textarea with php

Discussion in 'PHP' started by w3method, Apr 25, 2012.

  1. #1
    Hey guys, can anyone give me some advice on how to send multiple keyword values from a single textarea to be processed at the same time?

    basically what I have is a keyword list stored in a text file, I have the file stored on the server where the client can type in something like 30 keywords hit submit and it will return the rank of the keywords the client enters. I have it working perfectly for a single word, but I have no clue how to do multiple values?

    This is what I have so far. Any help would be greatly appreciated!

    
        <?
        define("FILE_NAME", "terms.txt");
        function Read()
        {
        echo @file_get_contents(FILE_NAME);
        };
        function Write()
        {
        $data = $_POST["term"];
        @file_put_contents(FILE_NAME, $data);
        }
        ?>
        
        <?
        if ($_POST["submit_check"])
        {
        Write();
        }
        ?>   
        
        <?
     	if ($_POST["search_submit"]){
    		$text = str_replace("\r", "", $_POST['term']);//to process the windows new line
    		$arrtext = explode("\n", $text);// create array of keywords
    		foreach($arrtext as $keyword)
    	
    		{
    		echo "keyword: $keyword<br />";//process the keywords as you like 
    		} 
    	};
    
        ?>          
     
     <form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post">  Mulitple Keywords :<br>
            <textarea cols="100" rows="30" name="term"><? Read(); ?></textarea><br>
            <input type="submit" name="submit" value="Update text">
            <input type="hidden" name="submit_check" value="1">
            <input type="submit" name="search_submit" class="search-submit" value="Go">
    
            </form>
    	<?
            if ($_POST["submit_check"]){
                echo 'Text updated';
            };
            ?>      
            
    PHP:

    This is what the form field looks like:

    NCrEy.jpg
     
    w3method, Apr 25, 2012 IP
  2. paparts

    paparts Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    I did not get what you mean... Your scipt looks fine...
     
    paparts, Apr 26, 2012 IP
  3. Arttu

    Arttu Member

    Messages:
    139
    Likes Received:
    2
    Best Answers:
    8
    Trophy Points:
    40
    #3
    Put the ranking function inside the for loop.
     
    Arttu, Apr 26, 2012 IP