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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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; > } |
|
|||
|
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/ |