Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP string to boolean function?

Featured Replies

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

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);

  • Author

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

  • Author

its okay ill just make my own function

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

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

 

 

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'.

Edited by PHP Monkey

  • Author

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

 

client insists i use boolean lol

  • Author

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

Edited by web-itec

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.