Web Design Forum: PHP string to boolean function? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP string to boolean function? Rate Topic: -----

#1 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 23 December 2011 - 09:58 PM

Hello, Ive looked everywhere for a function that can take a string and turn it into a boolean for example team NOT worker change to team -worker but not had much look finding one

im planning on using IN BOOLEAN MODE on mysql to get the people who meet the boolean search

Any help would be great,

Many Thanks, Gary
0

#2 User is offline   keevitaja 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 05-December 10
  • Reputation: 1

Posted 24 December 2011 - 01:43 AM

not sure, if i get what you want. boolen has only true or false. string with value turned into boolean is allways true!

<?php

$string = 'I am a string';

var_dump($string);

echo '<hr>';

$bool = (bool)$string;

var_dump($bool);

0

#3 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 24 December 2011 - 11:05 AM

View Postkeevitaja, on 24 December 2011 - 01:43 AM, said:

not sure, if i get what you want. boolen has only true or false. string with value turned into boolean is allways true!

<?php

$string = 'I am a string';

var_dump($string);

echo '<hr>';

$bool = (bool)$string;

var_dump($bool);



yes that gives true or false, im looking for the search boolean, for example a user searches cars NOT motorbikes, it would change it to cars -motorbikes for the sql in boolean mode
0

#4 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 24 December 2011 - 12:22 PM

its okay ill just make my own function
0

#5 User is offline   PHP Monkey 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 83
  • Joined: 25-July 11
  • Reputation: 6
  • Gender:Male
  • Location:Doncaster, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 28 December 2011 - 03:35 PM

View Postweb-itec, on 24 December 2011 - 12:22 PM, said:

its okay ill just make my own function


Heres a starting point.

<?php

function format_query_criteria($string) {
	$string = preg_replace('/(not\s)/i', '-', $string);
	return $string;
}

echo format_query_criteria("Cars NOT motorbikes");
// echos: Cars -motorbikes

0

#6 User is offline   webdesigner93 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,976
  • Joined: 22-September 09
  • Reputation: 222
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 28 December 2011 - 05:51 PM

View Postweb-itec, on 24 December 2011 - 12:22 PM, said:

its okay ill just make my own function

why not just forget the Boolian stuff and do plain old full text searching lol
0

#7 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 28 December 2011 - 08:05 PM

View Postkeevitaja, on 24 December 2011 - 01:43 AM, said:

not sure, if i get what you want. boolen has only true or false. string with value turned into boolean is allways true!

<?php

$string = 'I am a string';

var_dump($string);

echo '<hr>';

$bool = (bool)$string;

var_dump($bool);




View PostPHP Monkey, on 28 December 2011 - 03:35 PM, said:

Heres a starting point.

<?php

function format_query_criteria($string) {
	$string = preg_replace('/(not\s)/i', '-', $string);
	return $string;
}

echo format_query_criteria("Cars NOT motorbikes");
// echos: Cars -motorbikes





Both you fail lol because you didn;t read the question :)

The op is talking about full text searching using MySQL - all the boolean operators are built into MySQL - why you'd both go and make more work is beyond me :(

For instance, say you wanted everything from a table called "food", where the title and description columns contained the letters "chips" , but not "bread":

SELECT `id`, `title`, `date`, `description`
FROM `food` 
WHERE MATCH(title, description) AGAINST ('+chips -bread' IN BOOLEAN MODE)


You could even taking the matching further to include, exclude mutliple words, include/exclude a full word, force certain words/phrases to have a higher/lower contribution to the relevance score etc. E.g. the basis of a fairly comprehensive search function form. So using full text searching you could easily have a search form to display results:

- has a input to enter a list words where you want contained (E.g. any)
- has an input for a list of words you don't want included
- has an input for a list of words you do want included

etc.
0

#8 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 28 December 2011 - 08:06 PM

View Postweb-itec, on 24 December 2011 - 12:22 PM, said:

its okay ill just make my own function


Sure I've just read somewhere that you said you have 6 years php experience. If so, you've done very well to not have come across full text searching.
0

#9 User is offline   PHP Monkey 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 83
  • Joined: 25-July 11
  • Reputation: 6
  • Gender:Male
  • Location:Doncaster, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 28 December 2011 - 09:20 PM

View Postweb-itec, on 24 December 2011 - 11:05 AM, said:

yes that gives true or false, im looking for the search boolean, for example a user searches cars NOT motorbikes, it would change it to cars -motorbikes for the sql in boolean mode



View Postrallport, on 28 December 2011 - 08:05 PM, said:

Both you fail lol because you didn;t read the question :)



No I didn't.

He wanted a way to convert "Cars not motorbikes" into "Cars -motorbikes", thats what that function I wrote does. If someone types in 'Cars not motorbikes', it will convert 'not ' into '-' for the query.

By the way when using full text searching, using the + sign isn't needed, typing '+chips -bread' is the same as 'chips -bread'.

This post has been edited by PHP Monkey: 28 December 2011 - 09:28 PM

0

#10 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 29 December 2011 - 08:54 PM

View PostPHP Monkey, on 28 December 2011 - 09:20 PM, said:

No I didn't.

He wanted a way to convert "Cars not motorbikes" into "Cars -motorbikes", thats what that function I wrote does. If someone types in 'Cars not motorbikes', it will convert 'not ' into '-' for the query.

By the way when using full text searching, using the + sign isn't needed, typing '+chips -bread' is the same as 'chips -bread'.


Why so touchy? It's nearly new years eve.

Anyways, have a read of the fulltext docs and you'll get what I mean.
0

#11 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 29 December 2011 - 10:42 PM

View Postwebdesigner93, on 28 December 2011 - 05:51 PM, said:

why not just forget the Boolian stuff and do plain old full text searching lol


client insists i use boolean lol
0

#12 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 29 December 2011 - 10:45 PM

View Postrallport, on 28 December 2011 - 08:06 PM, said:

Sure I've just read somewhere that you said you have 6 years php experience. If so, you've done very well to not have come across full text searching.


well ive been learning/coding for 6 years yes, i have came across it and i have messed about with +this -that but i have never had to use it in a website i have made but this particular client now insists i have a boolean search

EDIT
just so you know i encouraged the client in the end that boolean search isnt really essential so ive not done it now as couldnt be bothered making the function when there was no gain from it for either me or the client but if anyone has got a function that does it then please let me know as its better for him to have than not

This post has been edited by web-itec: 29 December 2011 - 10:49 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users