GetDotted Domains

Viewing Thread:
"PHP error - one for the php experts."

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Mon 14/03/05 at 15:30
Moderator
"Are you sure?"
Posts: 5,000
I'm sure one of you PHP wizards will be able to help - I can only just about cut + paste PHP so I'm struggling!

I'm using some PHP code from CJ Webdesign for a simple website Search Engine.
I've got everything working but when I try searching for word + another the '+' symbol creates loads of errors (so does *).

The errors are reported in line 38 (preg_match)

You can see the script errors at [URL]http://www.hmmm.ip3.co.uk/search/[/URL]
Search for: freeola test then freeola + test

Thanks in advance - code here: (freeola forum police stop the long fields being posted [URL]http://www.hmmm.ip3.co.uk/cgi-bin/axs/ax.pl?http://www.hmmm.ip3.co.uk/search/code.shtml[/URL]
Tue 15/03/05 at 09:45
Moderator
"Are you sure?"
Posts: 5,000
Nimco wrote:
> What exactly are you searching? Is it a MySQL database, and if so,
> what version of MySQL are you running?
>
> I only ask this since more recent versions of MySQL support boolean
> searching and may be what you are looking for...

No there's no DB, just flat files.

I'm playing with a website for a town planning company who want a simple (and cheap) search option. A visitor needs to be able to stick in a reference number, area or postcode and be presented with a list of results.

This script can provide that, but it may be too simplistic. I would like a site search that resturns the results with thumbnail images attached and with a few more frilly bits. My problem is costs, I'm trying to find free CGI/Perl/PHP/Javascript scritps that are any good.


EDIT:
Managed to add this to the code(not my coding)so the script now searches for partial words (free finds freeola) and automatically applies AND to the keywords:
$weight = 0;
foreach ($keywords as $word){
if(preg_match ("/$word/i", $temp[3]) || preg_match ("/$word/i", $temp[0])) {
$weight++;
}
}
$wordCount = count($keywords);
if($weight == $wordCount) {
$lis++;
$collect[$lis] = $line[$x];
}
Tue 15/03/05 at 02:14
Regular
"Devil in disguise"
Posts: 3,151
Hmmm... wrote:
> I laughed when I read your last message - I've re-read everything and
> I don't think you actually told me that solution - just said you had
> it ready... If you did I missed it and apologise.
>

Oh, I was referring to what I originally posted about escaping the special characters with \, just in the end didn't see any point in keeping them so just deleted them instead. Going for the cheap fix just wasted time, should have not been so idle and given you the proper solution in the first place.
Tue 15/03/05 at 00:19
Regular
"NULL"
Posts: 1,384
What exactly are you searching? Is it a MySQL database, and if so, what version of MySQL are you running?

I only ask this since more recent versions of MySQL support boolean searching and may be what you are looking for...
Mon 14/03/05 at 21:17
Moderator
"Are you sure?"
Posts: 5,000
Garin wrote:
> Perhaps a better approach was to do what I suggested in the first
> place and try this.
> After
> $keyword = $_POST['keyword'];
> Put
> $keyword = preg_replace('/[^a-zA-Z0-9\s]/', '', $keyword);

Garin - THANKS! All working now...

I laughed when I read your last message - I've re-read everything and I don't think you actually told me that solution - just said you had it ready... If you did I missed it and apologise.

You're right it is a simple search engine script but hopefully it's going to help me out with a site I'm doing. Basically you have to tell the engine what to index (i.e. all the key words) then a user can only find what you want them to - perhaps a reference number or a post code.

Anyway thanks again - good work!
Mon 14/03/05 at 20:47
Regular
"Devil in disguise"
Posts: 3,151
Hmmm... wrote:
> Of course there's always another problem.
> This works: freeola test
> Now this works: freeola + test
>
> But for some boolean logic visitors they might still try: freeola
> +test which causes the error again.

Ultimately you're hitting the limits of the scipt you're using. Perhaps a better approach was to do what I suggested in the first place and try this.
After

$keyword = $_POST['keyword'];

Put

$keyword = preg_replace('/[^a-zA-Z0-9\s]/', '', $keyword);

It basically filters out anything thats not a letter of the alphabet, a number or a space. The script isnt really set up to support complex searches anyway, so better just filter out anything causes trouble.
Mon 14/03/05 at 20:00
Moderator
"Are you sure?"
Posts: 5,000
Garin wrote:
> Seems it not my day...really sorry :( I put the ) in the wrong place.
> The line is this:
>
> if (strlen($word)<= 1) { continue; }
>
> I just wrote out another solution for you too until it just struck me
> what I'd done. :P Hopefully not needed now.

I'm all bracketed out!

You're last post works !!! Thanks for that - you certainly know your PHP.

Of course there's always another problem.
This works: freeola test
Now this works: freeola + test

But for some boolean logic visitors they might still try: freeola +test which causes the error again.

EDIT: I've updated the code below with your latest fix.
:( or is that :{
Mon 14/03/05 at 19:39
Regular
"Devil in disguise"
Posts: 3,151
Seems it not my day...really sorry :( I put the ) in the wrong place. The line is this:

if (strlen($word)<= 1) { continue; }

I just wrote out another solution for you too until it just struck me what I'd done. :P Hopefully not needed now.
Mon 14/03/05 at 19:13
Moderator
"Are you sure?"
Posts: 5,000
Garin wrote:
> Oops sorry, careless error, the line is missing a closing ) it should
> be
> if (strlen($word<= 1)) { continue; }

Better ! No errors but now the search script doesn't actually find anything - i.e. It's not working... (NB. I'm testing this in a different domain, the links still point to the original problem)

Could your idea for word be used at the top of the code, line 11 which check for the keyword?

if(strlen($_POST['keyword']) <= 3){

Thanks again.
Mon 14/03/05 at 18:36
Regular
"Devil in disguise"
Posts: 3,151
Oops sorry, careless error, the line is missing a closing ) it should be
if (strlen($word<= 1)) { continue; }
Mon 14/03/05 at 18:28
Moderator
"Are you sure?"
Posts: 5,000
Garin - Thanks for the reply. Unfortunately I can't get your code to work - keep getting syntax problems with unexpected { for the line I add your code on.

Tried amended things - but failed so far...

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

First Class!
I feel that your service on this occasion was absolutely first class - a model of excellence. After this, I hope to stay with Freeola for a long time!
Wonderful...
... and so easy-to-use even for a technophobe like me. I had my website up in a couple of hours. Thank you.
Vivien

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.