Browser.php updated to v1.6
Version 1.6 of Browser.php has been released with a lot of updates: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/
Version 1.6 of Browser.php has been released with a lot of updates: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/
For those of you who detect Opera 10’s user agent, the Opera team has provide some “fun” for all of us. In my Browser project I started getting feedback that it was broken. At the 10,000′ level, it was defintely broken because the Browser project was returning version 9.8 for Opera version 10.
This is because the Opera dev team decided to leave the version 9.8 user agent string the same and tack on version 10 to end of the string. You can read more about it on their blog.
For those of you using my Browser project have no fear; the new version (1.6+) handles the oddity!
In the Browser.php project John pointed out (in the comments) a terrible typo in the source. I imagine no one has encountered this before as it only effects v1 or v1.5 of Internet Explorer.
Typo updated and version 1.5 of Browser.php released: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/
A while back I wrote a semi-popular post on removing images from a WordPress post — today I am revisiting it. The original solution used the_content() and the output buffer to remove the images out of the post. Now that I have used WordPress a bit longer and candidly had to use the solution again and thought “what was I thinking” I thought I would share the cleaner solution:
. . . <?php echo preg_replace('/<img[^>]+./','',get_the_content()); ?> . . .
I released v1.4 of the Browser.php project today to address a few features suggested by readers. This new release adds support for GoogleBot, Yahoo! Slurp, and the W3C Validator.
Check out version 1.4: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/
Based on a comment on the Browser.php page I added support for the iPod today. I opted to place both the iPhone and iPod as browsers even though they are likely using the same instance of Safari. Additionally I added support for the iPod and iPhone as platforms. Thanks for the comments; enjoy!
The browser detection project in php (Browser.php) has been updated to version 1.2 based on suggestions I received in the comments. The new version is available for download in the project pages.
Thanks to all those who have emailed and commented on the script.
I updated the Browser.php class today to detect Google’s Chrome Browser. Additionally, thanks to an idea from Daniel ‘mavrick’ Lang, I added isBrowser($browserName) as a function to version 1.1.
Visit the Browser.php class page today to grab the update!
Interested in a PHP4 version? Daniel is maintaining a version for PHP4.
Example Usage:
1 2 3 4 5 6 7 8 9 10 11 12 | $browser = new Browser(); if( ! ( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) ) { echo 'You have FireFox version 2 or greater'; } // AND NOW... if( $browser->isBrowser(Browser::BROWSER_CHROME) ) { echo '<p><strong>Hi Google Chrome User!</strong></p>'; } |
A few people have contacted in the past about what I did to get IDs to work on Peter’s Script over at vulgarisoips.com (see the original post here).
Peter’s script works great; but for my needs I had to add an ID to the suggestion as a way to relate the selected value back to a dB entry.
First, I needed a way to tell the script where to add the results to in the DOM instead of having the script add the object automatically. I created a new option called attachObject which allowed me to control the object in the DOM. This allowed me to do this:
$('#name').suggest('/suggest/client',{dataContainer:'#cid', attachObject:'#sresults', onSelect: myFunction );
Note how above I use #sresults as my object to attach the suggestion results to. In my edits if you leave out the attachObject it will still build the <ul> object for you without any issues.
Next, I needed a way to have the ID go along with the representation values (ex. a hash-like key, value relationship). To do this I added two other options to the script: one called dataContainer and one called dataDelimiter which I set to a default value of tab (\t). The dataContainer is an ID of an input box which holds the database ID of the selected object in the suggest box. The dataDelimiter is the delimiter for the payload which contains the key values pairs separated by the dataDelimiter. (Note: the “row” delimiter is still a new line character).
In my XHTML I have this:
<input type="hidden" name="cid" id="cid" value="-1"/> <input type="text" id="name" size="30" maxlength="128"/> <div id="suggestResults"></div>
(and I use the script stub above…)
On the server I have /suggest/client do something similar to this:
. . . $stmt->execute(); foreach( $stmt->fetchAll(PDO::FETCH_OBJ) as $row ) { echo "{$row->displayName}\t{$row->tmpid}\n"; }
NOTE: I do make an assumption your keys will always be unique; as I append a s_ to the key to construct the necessary <li> items (need to keep them unique for DOM reasons).
Here is the original version of Peter’s script: Original Version 1.1 (in text)
Here are my updates (let us call it v1.2):Updated Version 1.2 (in text)
In hindsight there are definitely better ways to do this but this solution is working great still (this idea and solution go back to August of 2007); and I will always suggest “working effectively in production” is always better than how it “should be.”
In an attempt to add the PECL Upload Progress package, I received the following error:
[root@zebra cbschuld]# pecl install uploadprogress-beta downloading uploadprogress-0.3.0.tgz ... Starting to download uploadprogress-0.3.0.tgz (4,677 bytes) .....done: 4,677 bytes 3 source files, building running: phpize sh: phpize: command not found ERROR: `phpize' failed
Hmmm, it turns out I never added the package php-devel (oops). If you are missing phpize on your machine add it with:
yum install php-devel