problem writing text search function

This is a discussion on problem writing text search function within the PHP Language forums, part of the PHP Programming Forums category; PHP use the keyword "return" for returning a value from a function. And variables are not global by ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 01-10-2004
Chung Leong
 
Posts: n/a
Default Re: problem writing text search function

PHP use the keyword "return" for returning a value from a function. And
variables are not global by default. Hence:

function textsearch($the_items_description)
{
global $search_for;

$pos = strpos($the_items_description, $search_for);

if ($pos === false) {
return false;
} else {
return true;
}
}

or shorter:

function textsearch($the_items_description)
{
global $search_for;

$pos = strpos($the_items_description, $search_for);

return ($pos !== false);
}

or shorter still:

strstr($the_items_description, $search_for);

Uzytkownik "Matthew Robinson" <mattyrobinson69@hotmail.com> napisal w
wiadomosci news:pan.2004.01.09.20.48.56.405332@hotmail.com...
> i get "Parse error: parse error in /home/houseproudlancs_co_uk/search.php
> on line 65" when i open the page, line 65 would be the line that starts
> with if (textsearch
>
> $search_for = "is";
> $the_items_description = "this is where the description would go";
> if (textsearch($item_category) == true {
> echo ("correct");
> } else {
> echo ("incorrect");
> }
>
>
> function textsearch($the_items_description)
> {
>
> $pos = strpos($the_items_description, $search_for);
>
> if ($pos === false) {
> textsearch = false;
> } else {
> textsearch = true;
> }



Reply With Quote
  #12 (permalink)  
Old 01-16-2004
Geoff Berrow
 
Posts: n/a
Default Re: problem writing text search function

I noticed that Message-ID: <pan.2004.01.09.22.58.44.430581@hotmail.com>
from Matthew Robinson contained the following:

>$search_for = "is";
>$the_items_description = "this is where the description would go";
>if (textsearch($item_category)) == true {
>echo ("correct");
>} else {
>echo ("incorrect");
>}


well you know it should be

if (textsearch($item_category) == true){...}

now, but for this test did you not perhaps mean to write

$item_category = "this is where the description would go";
if (textsearch($item_category == true)) {...}
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:17 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0