R4z3r Posted March 21, 2013 Share Posted March 21, 2013 Hey, I was wondering if there was a good way to leverage the search autocomplete via PHP. I am looking to add easy timezone support to my workflow (based on these timezones — http://www.php.net/manual/en/timezones.php). I would like to make a PHP array with autocomplete suggestions for the user to make it easier for them to set the timezone. I believe I could use PHP's levenshtein function to find the closest matches to the input, but was wondering if there is a better way of doing this before passing it to the script to save to the JSON config file. I would like, if possible, to first autocomplete the country, then once the backslash appears to begin matching against the locations in that country. If there is a best way to utilize alfred to do this, please let me know. If not, I can use a combo of levenshtein and conditionals I think to do it. It may not be hard to modify one line of code, but anyway to make it easier for people is better. Thanks! Amoftcoorb 1 Link to comment
Tyler Eich Posted March 21, 2013 Share Posted March 21, 2013 Hey, I was wondering if there was a good way to leverage the search autocomplete via PHP. I am looking to add easy timezone support to my workflow (based on these timezones — http://www.php.net/manual/en/timezones.php). I would like to make a PHP array with autocomplete suggestions for the user to make it easier for them to set the timezone. I believe I could use PHP's levenshtein function to find the closest matches to the input, but was wondering if there is a better way of doing this before passing it to the script to save to the JSON config file. I would like, if possible, to first autocomplete the country, then once the backslash appears to begin matching against the locations in that country. If there is a best way to utilize alfred to do this, please let me know. If not, I can use a combo of levenshtein and conditionals I think to do it. It may not be hard to modify one line of code, but anyway to make it easier for people is better. Thanks! The levenshtein function is quite useful. I have also used this code: $fuzzy = preg_replace('/(.)/', '$1.*', $query); preg_match("/$fuzzy/i", $haystack); It's been a while since I used this (and it may not work as I expect), but it's supposed to replace each character with the character and a fuzzy space .* R4z3r 1 Link to comment
jdfwarrior Posted March 21, 2013 Share Posted March 21, 2013 Are you wanting the user to be able to set THEIR timezone? Reason I ask is, you can actually read that from the system without having to ask the user to set it. Link to comment
R4z3r Posted March 21, 2013 Author Share Posted March 21, 2013 Are you wanting the user to be able to set THEIR timezone? Reason I ask is, you can actually read that from the system without having to ask the user to set it. Reading the default timezone through PHP though equates to errors since PHP timezones aren't set. How would I ask Alfred for this information? Also, would this be able to read in the system clock preferences for 12-hour vs. 24-hour time? Link to comment
jdfwarrior Posted March 21, 2013 Share Posted March 21, 2013 In PHP: $tz = exec( 'systemsetup -gettimezone | cut -d " " -f 3 ' ); That reads the timezone that the machine is set to. In my case, this returns "America/Chicago". So you could set the default timezone by doing.... $tz = exec( 'systemsetup -gettimezone | cut -d " " -f 3 ' ); date_default_timezone_set( $tz ); Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now