graat90 Posted January 10, 2014 Share Posted January 10, 2014 Hi there, I've searched around for the same problem that i'm dealing with, but i couldn't find the exact answer yet. What i want, is that if an user clicks on a button, the word in front of it has to be added at a new line (vulwoorden.txt). I think i'm almost there, but i'm not able to attach the button to the generated Twitter word. The meaning of this all is, that an admin is able to make his own word filter. So if he clicks the verberg item button (hide word button), the application should not only hide this word from the html side, but also add this word to the textfile. The application now opens the existing textfile and already filters out the given words. But i want the user to be able, to add new words to this textfile after button click! This is the code so far: public function DisplayMostUsedWords(){ echo "<h3>Most used words</h3>"; asort($this->word_occurence); $this->word_occurence = array_reverse($this->word_occurence); $i=1; // filter out commonly used words $handle = fopen("./includes/vulwoorden.txt", "r"); while (!feof($handle)) { // Get the current line that the file is reading $current_line = trim(fgets($handle)); unset($this->word_occurence[$current_line]); } fclose($handle); foreach($this->word_occurence as $word => $occurence){ echo "<ul class=\"list-group\"> <li class=\"list-group-item\"> <table id=\"most-used-words\"> <thead> <tr> <td>$occurence - $word</td> <td><a href=\"#\" style=\"float:right;\" class=\"btn-danger btn-sm\">Verberg term</a></td> </tr> </thead> </table> </li> </ul>"; $i++; if($i >= 10){ break; } } This what it's look like : I hope i explained it clear! Thanks in advance Quote Link to comment Share on other sites More sharing options...
graat90 Posted January 13, 2014 Author Share Posted January 13, 2014 Nobody? Quote Link to comment Share on other sites More sharing options...
graat90 Posted January 13, 2014 Author Share Posted January 13, 2014 I was thinking to do something like this, but it's not the best way i think: foreach($this->word_occurence as $word => $occurence){ echo "<ul class=\"list-group\"> <li class=\"list-group-item\"> <table id=\"most-used-words\"> <thead> <tr> <td>$occurence - $word</td> <td>"; if (isset($_POST['<a href=\"#\" style=\"float:right;\" class=\"btn-danger btn-sm\">Verberg term</a>'])) { file_put_contents('./includes/vulwoorden.txt', $word , FILE_APPEND | LOCK_EX); }"</td> </tr> </thead> </table> </li> </ul>"; $i++; if($i >= 10){ break; } } Quote Link to comment Share on other sites More sharing options...
Solution graat90 Posted January 13, 2014 Author Solution Share Posted January 13, 2014 This topic can be closed. I solved the problem. foreach($this->word_occurence as $word => $occurence){ $fn = "./includes/vulwoorden.txt"; $file = fopen($fn, "a+"); $size = filesize($fn); if(isset($_POST['toevoegen'])) fwrite($file, $_POST['toevoegen']); fclose($file); ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <br /> <table> <tr> <td><?=$occurence?></td> <td style="padding-left: 11px;"><input style="background-color: transparent; border: none;" class="field left" readonly type="text" name="toevoegen" value="<?=$word?>"/></td> <td><input class="btn-danger btn-sm" type="submit" value="Verberg term"/></td> </tr> <table> </form> <? $i++; if($i >= 10){ break; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.