|
|
|
| |||||||||
| View Poll Results: Did you find this useful? | |||
| Yes | | 0 | 0% |
| No | | 0 | 0% |
| Voters: 0. You may not vote on this poll | |||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
||||
|
||||
|
Hi
I am Hamish and I am 12. I programmed this script all myself. As the title says, there is no SQL needed, no HTML/PHP code displayed and titles as well. First make a form (GET or POST) with an input name of searchstring . Now we start to program the script. We start the PHP session and head straight off by doing a simple query to tell if anything has been entered and echoing a search header. PHP Code:
Now we define some variables. First the contents file. This is in the format of: Code:
filename.ext|Title filename.ext|Title etc. You can rename the contents file to your choice. Next we put all the contents lines into an array with the file function. After that we do a foreach for all the lines and get rid of the newline character. We also put in the unique title feature, by listing variables and splitting by a slashed-out pipe. We need the [0] at the end of the split string so as not to generate 'Array' errors. Finally we open the filename part of the list. PHP Code:
Next we do an fopen and fread with an if to tell if the searchstring is contained in the file. PHP Code:
We put in a nice file header and use the $check variable we defined using file function with a foreach. We then strip all the tags from that. Next we check if the searchstring is in that line. PHP Code:
Here comes the good part.We explode the line by a space, so exploding it into words. We then echo a ... for the line start and for each of the words, check if the searchstring is in them. If it is, then echo it in bold. Otherwise, just echo it. PHP Code:
Now all we do is finish off all the many constructs, add some new lines and finish the PHP session. PHP Code:
Here is the whole code: PHP Code:
I hope you have found this useful. You can use the poll included, 1 for yes, 2 for no. Please feel free to drop me a line at hamishcool3@yahoo.co.uk Cheers, Hamish |
![]() |
| Viewing: Codewalkers Forums > Other > Tutorials > REQUEST: Simple search without SQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|