I’m getting a string from a $_GET and I want to test if it could be a boolean, before I use it for a part of a mysql query. Is there a better way of doing it than: Answer There’s, by the way, a cleaner way of writing it: But yes. The one you wrote down is the only way.
Tag: php
Building custom PHP extension (.so)
I own a high traffic website that does business in the USA and Canada. We have lots of servers but I want to make sure it’s 100% available with no latency whatsoever. I’ve learned about creating custom extensions (I know a little C) and I want to create custom validation/files (since php extension…
PHP XOR Decryption
I have an encrypted parameter V coming from a web page like this: V is encrypted like above: MD5 : XOR : which gives something like: what I want here is the function to decrypt this ‘ecryptedXOR’ using the password, so that I can get the: here’s what I’ve done so far: http://pastebin.c…
subtract 6 hours from date(‘g:i a’, strtotime($time_date_data));
I am using the following code to transform a universal time code into something a little more user friendly. But now I need to subtract 6 hours from meeting_time. Should I do it after the code above or can I work it into the same date function? Something like: Answer String-to-time (strtotime) returns a Unix …
Select Random Row from SQL Using PHP
I want to request 5 random rows from my SQL table using php. for instance, i need to: Answer Edit: For what its worth, Please note that using rand() on a table with large number of rows is going to be slow. This can actually crash your server. Some Solution: MediaWiki uses an interesting trick (for Wikipedia&…
How to send file from PHP-script to another PHP-script in code?
I have some web-form which posts some data and user file to first php script. First script wants to upload received from form file which located at $_FILE variable to second php script (second script …
Adding PostgreSQL support to already installed PHP
I have php-5.3.6 and postgresql installed in my Fedora 13. But it seems that postgresql support is not enabled in php. My phpinfo() page doesn’t show any PostgreSQL section, neither pdo_pgsql section. …
Split string on dots not preceded by a digit without losing digit in split
Given the following sentence: I want preg_split() to give this: I am using: But this gives me: As you can see, the last character of each sentence is removed. I know why this happens, but I don’t know how to prevent it from happening. Any ideas? Can lookaheads and lookbehinds help here? I am not really …
array_uintersect() gives unexpected results when callback only returns 0 or 1
I have a custom callback in my array_uintersect() call because I need to case-sensitively compare strings in two elements while comparing rows between two multi-dimensional arrays. OUTPUT I can’t understand why this code doesn’t produce the correct output which should be an array with “BR…
Standard Practices in Detecting Mobile Devices and Feeding Pages in PHP and jQuery
I see that mobile versions of websites often begin with an “m.” (e.g. http://m.accuweather.com). I’d like to redirect my mobile users to http://m.mysite.com so that I can display a different page. What’s the standard practice way to feed mobile devices the mobile version of a site? Doe…