Well for some reason i can't seem to find this script anywhere.
So what i need is a search form, you type in what you want to find in the TXT file in the textbox, hit submit and it highlights that text in the TXT file.

I can do the Form with the textbox if need be.
So, thanks.
And sorry, this probably is the wrong section. Its kinda newbie ha.

    You can get the contents of a TXT file and put it in a string variable with [man]file_get_contents[/man].

    You can then use [man]preg_replace[/man] to take the string variable and replace some search string with one containing highlighting.

      Well, i did that. Here is what i came up with:

      
      <?php
      $homepage = file_get_contents('http://******/**.txt');
      echo $homepage;
      $string = '$_POST["search"];'
      $pattern = '/(\w+) (\d+), (\d+)/i';
      $replacement = "<B>".$_POST["search"]."</b>";
      echo preg_replace($pattern, $replacement, $string);
      ?>
      

      And the HTML bit.

      <html>
      	<form action='search.php' method='GET'>
      		<font face='sans-serif' size='5'>
      		<center>
      				My Search Engine. <br>
      				<input type='text' size='50' name='search'> <input type='submit' name = 'submit' value='search'>
      		</center>
      		</font>
      	</form>
      </html>
      

      And the error:

      Parse error: syntax error, unexpected T_VARIABLE in /htdocs/search.php on line 6

      I have removed the website for my reasons 😉
      And then i kinda figured it was the <b> tags, so i searched for the writes ones.
      And it gave me that code, but with the same error.
      So eh.

        look at the line that starts $string

          Yeah figuring out syntax errors is pretty basic. The error even tells you which line.

          Also, you are not putting your search string in your pattern. You are just searching for...gosh not even sure what.

            Ok as i said im kinda newbie at this stuff.
            Can someone give me some help with the code or just tell me where it is.
            Which i knew where it was i just didn't know how to fix it.

              $string = '$_POST["search"];'

              Those '..' should not be there.
              Compare it for example with this line

              $replacement = "<B>".$_POST["search"]."</b>";

              and see how the syntax highlighting is different.

              Getting the syntax right in PHP is the easiest part. Even easier than in English, in fact.

                Ok i used that new code without the '..' and it worked, kinda.
                But it doesn't display the data from the Textbox as bold. It just displays the Text file.

                  Did you read the documentation on [man]preg_replace[/man]?

                    Yes, but as i said im not that good at PHP.
                    So i read it, and really couldn't understand it.
                    So i looked for something that might of worked, thats what i ended up with.

                      Write a Reply...