Mar 09 2008

jQuery: using jquery.autocomplete.js plugin in noConflict mode

Tag: JavaScript, Programming, Tech, jQueryjs @ 4:48 pm

When attempting to implement Dylan Verheul’s excellent auto-complete jQuery plugin on a project, I ran into problems due to the fact that we are using noConflict mode for jQuery by calling noConflict(); A few quick minutes poking around jquery.autocomplete.js and I had updated it to work in both noConflict and standard modes. For those of you looking to use jquery.autocomplete.js in noConflict mode, I’ve made it available for download here: jquery.autocomplete.js

UPDATE: Dylan has updated jquery.autocomplete.js to be compatible with noConflict mode. It also contains additional bug-fixes and improvements. You can download it at: http://code.google.com/p/jquery-autocomplete/source/browse/trunk/jquery.autocomplete.js

—————-
Now playing: AFX - SteppingFilter 101
via FoxyTunes

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Feb 18 2008

PHP & ionCube Loader: ‘The Loader must appear as the first entry in the php.ini file in Unknown on line 0′

Tag: Apache, Linux, PHP, Techjs @ 3:00 pm

I received the following in my Apache error_log when attempting to load the ionCube loader in my php.ini file:

PHP Fatal error: [ionCube Loader] The Loader must appear as the first entry in the php.ini file in Unknown on line 0

This is because ionCube must be loaded before any of the Zend extensions are. So if you have the Zend extension/optimizer loaded, your php.ini should look like this to get ionCube to work:

[Zend]
zend_extension=/usr/local/ioncube/ioncube_loader_lin_5.1.so
zen_extension_ts=/usr/local/ioncube/ioncube_loader_lin_5.1_ts.so
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.0
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.0
zend_optimizer.version=3.3.0a
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so

—————-
Now playing: Tommy McCook & The Aggrovators - A Loving Melody
via FoxyTunes

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Dec 06 2007

mod_rewrite & PHP: How to match urlencoded plus sign (+ = %2B)

Tag: Apache, PHP, Programmingjs @ 9:37 pm

I ran into trouble when trying to pass a urlencode()‘ed plus sign into a web address being processed by mod_rewrite.

$url = ‘http://www.server.com/browsealpha/name+has+plus+in+it/’;
$url = urlencode($url); // http://www.server.com/browsealpha/name%2Bhas%2Bplus%2Bin%2Bit/

This $url variable gets echo()’d as a link in a page, so once it’s clicked and loaded in the browser, I then needed mod_rewrite to translate that to the actual URL, which is:

http://www.server.com/browsealpha.php?name=name%2Bhas%2Bplus%2Bin%2Bit

Here is the RewriteRule I was using to match:

# match any name containing any combination of letters, numbers, and the % sign (to match urlencoded URLs)
RewriteRule ^browsealpha/([%\w]*)/?$ /browsealpha.php?name=$1 [QSA,L]

This rule should match http://www.server.com/browsealpha/name%2Bhas%2Bplus%2Bin%2Bit/ but for some reason it wouldn’t work. After hours of frustration, I found a few threads mentioning the need to urlencode the string twice, like so:

urlencode(urlencode($variable));

IT WORKS!!! Apparently this is because mod_rewrite automatically decodes the urlencoded URL, so if you pass in %2B, PHP sees it as %2B0. If you double encode, mod_rewrite decodes the first one, and PHP receives the second one (which is now %2B, which is what we want).

—————-
Now playing: Autechre - 444
via FoxyTunes

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Dec 04 2007

jQuery: How to set one <select> element to the value of another (using onchange equivalent)

Tag: JavaScript, Programming, jQueryjs @ 5:33 pm

Say you have an HTML <select> form element and you want to set another <select> element equal to the first one when it changes. Here’s an easy way to do so with jQuery:

$(’#id_of_select1′).change(function() {
    var select1_value = $(this).val();
    $(’#id_of_select2′).val(select1_value);
});

—————-
Now playing: Drexciya - Astronomical Guidepost
via FoxyTunes

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Dec 04 2007

jQuery: How to get the ID of your current object.

Tag: JavaScript, Programming, jQueryjs @ 4:14 pm

Say you want to know the ID of your current jQuery object. You can achieve this easily using jQuery’s attr() method:

var current_id = $(this).attr(’id’);

This will only work provided that you have a valid jQuery object $(this) that you are working with, eg:

$(document).ready(function() {
  $(’input.text’).focus(function() {
    $(’input.text’).removeClass(’onFocus’); /* remove focus state from all input elements */
    $(this).addClass(’onFocus’); /* add focus state to currently clicked element */
    var current_id = $(this).attr(’id’);
  });
};

Using the code above, you will now know the ID of the currently focused input element. This can come in handy later on if you want to perform further actions on the element.

—————-
Now playing: Amon Tobin - Precursor (feat. Quadraceptor)
via FoxyTunes

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Jul 21 2007

PHP & imagettftext with Webcore TrueType fonts.

Tag: Fedora, Linux, PHP, Techjs @ 1:37 pm

If you’re trying to write some text using PHP/GD & the imagettftext function, you will of course need some TrueType fonts to work with. I’ve found a great set of fonts available for free: Webcore. Webcore contains all the fonts webdesigners constantly use, things like Arial, Tahoma, Verdana, Georgia, etc..

To install, simply download to your server and install the RPM (Fedora):

shell> wget http://avi.alkalay.net/software/webcore-fonts/webcore-fonts-3.0-1.noarch.rpm
shell> rpm -i webcore-fonts-3.0-1.noarch.rpm

These fonts will now be available to you in /usr/share/fonts/webcore/.

Make sure you specify the full path when calling imagettftext(), eg:

<?php

// Set the content-type
header(”Content-type: image/png”);

// Replace path by your own font path
$font = ‘/usr/share/fonts/webcore/arial.ttf’;

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = ‘Hello world!’;

// Add some text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

Your mileage may vary if you are using a different distribution, but the docs state that this RPM should work on other distros.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Mar 27 2007

Cookies with PHP’s setcookie() and Safari

Tag: PHP, Programmingjs @ 2:46 pm

I’ve come across a little inconsistency between browsers and the way they handle cookies. Using the examples from PHP’s online manual, I was unable to get Safari to remove cookies using setcookie(). All other browsers would clear the cookie with no problems. It turns out that Safari will only delete cookies if both the cookie name AND the cookie path match.

In other words, this won’t work:

setcookie(’TestCookie’, ’somevalue’, time()+3600, ‘/somepath/’); // Set cookie
setcookie(’TestCookie’, ”, time()-3600); // Delete cookie

But this will work:

setcookie(’TestCookie’, ’somevalue’, time()+3600, ‘/somepath/’); // Set cookie
setcookie(’TestCookie’, ”, time()-3600, ‘/somepath/’); // Delete cookie

Basically, if you set a cookie using a path, you must also specify the path when deleting the cookie. Safari won’t remove the cookie otherwise. This is probably a good thing.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Next Page »