Probably because of upgraded ports packages, self-compiled PHP on MAMP suddenly became not to find libjpeg and some libraries. There’s a way to upgrade to MAMP1.9, but I’ve decided to switch to use self-compiled 64bit PHP. Removed all macports packages. http://trac.macports.org/wiki/Migration % sudo port -f uninstall installed % sudo port clean –work –archive all For […]
Tag Archives: php
Don’t define json_encode with Zend_Json
Some web servers are still working with PHP5.1.6. That means json_encode/json_decode is not supported by default. Although some libraries are using json_encode, for instance php-sdk for facebook, so I defined json_encode like this: function json_encode($data) { return Zend_Json::encode($data); } I didn’t know that actually Zend_Json uses json_encode in their code, so badly it will be […]
jQuery plugin for Twitter OAuth via popup window (Facebook style)
Disqus and some applications are using Twitter OAuth, but their user flow is not sequential single window process. A child window comes up, then it shows twitter.com and user can click Deny/Allow through that popup. When the user hits the deny or allow button, the popup will be closed immediately and the parent window will […]
How to Make an Autobot on Twitter with OAuth, not Basic Authentication
Twitter will be shutting off basic authentication on their API on June 30. Tweeting with basic auth was pretty easy in PHP: $context = stream_context_create(array( ‘http’ => array( ‘method’ => ‘POST’, ‘header’ => ‘Content-type: application/x-www-form-urlencoded’, ‘content’ => http_build_query(array(’status’ => $status)), ), )); $response = file_get_contents("http://$username:[email protected]/statuses/update.xml", false, $context); After shut off basic auth, how can we […]
Compiling PHP5.3.2 on MAMP
It was not easy to compile PHP5.3.2 on MAMP. First of all, you need to download httpd2.0.63 and PHP5.3.2. (I’m using MAMP 1.8.2 and Mac OSX 10.5.8) MAMP is in /Application/MAMP already. You may want to backup that directory. You may need to edit srclib/apr/include/apr.h like “#define APR_HAS_SENDFILE 0” after run configure because get an […]
Convert multiple object to array in PHP
For simple object, just use cast syntax should be fine. $array = (array)$object; However, this way doesn’t work for complexed object (or array+object combination) like this: array(2) { [0]=> object(stdClass)#1 (1) { [“id”]=> int(0) } [1]=> object(stdClass)#2 (1) { [“id”]=> int(1) } } Then, simply this one liner works well. $multipleArray = array_map(’get_object_vars’, $complexedObject); Since […]
Complete working sample for Services_Twitter OAuth in PHP PEAR
You can get some sample codes for Services_Twitter with OAuth from php doc, but it’s not a complete code. I rewrote some parts. % pear install –alldeps Services_Twitter-alpha <?php if (isset($_GET[’clear’])) { // sometimes you need to clear session, just access ?clear=1 session_start(); $_SESSION = array(); session_destroy(); die(’session has been cleared.’); } define(’CONSUMER_KEY’, […]
Compiling mongo php driver on pecl for MAMP
MAMP 1.8.2 includes pecl but actually it doesn’t work. When trying to “pecl install mongo”, there will be an error. grep: /Applications/MAMP/bin/php5/include/php/main/php.h: No such file or directory So, I downloaded source tar ball of PHP 5.2.10 (same version as MAMP’s PHP) and configure && make && make install. Then $prefix/include directory will be created. Just […]
Load remote CSS file dynamically with jQuery
The below code loads a CSS file dynamically. It’s relatively easy to load all CSS files from the beginning, or just append a link element (ref. Switch stylesheets with jQuery). But it rarely needs to load a file dynamically and wait until those new CSS properties are ready to render new HTML elements. test.html: <html> […]