Archive for July, 2009

function array_flatten

July 28th, 2009 No comments

This is not much to brag about, still we had a very large dataset as variable dimensional and variable depth, which we wanted to be sent to a custom function using prototype.js. For the data exchange we use JSON, but the varying depth and related tags, made us to do like hell in the javascript templating that we had to find a method to flatten the array in such a way that each of the associative keys would not be mangled.

The final out come is function array_flatten

function array_flatten($p, $ki = ''){
    if($ki !== '') $ki .= '-';
    $rv = array();
    foreach($p as $k => $v){
            $rv = array_merge($rv, array_flatten($v, $ki.$k));
            $rv[$ki . $k] = $v;
    return $rv;

The flattened dataset, helped us to do rendering in less than half the iterations, and the application response was more better after using this.

Categories: PHP, Tips Tags:

Annoying php error related to headers

July 23rd, 2009 No comments

Cannot modify header information – headers already sent by (output started at /path/to/the/php/file.php:line) in /path/to/the/php/file.php on line newline

Okay the normal case would be to check the file thouroghly and make sure there is nothing that is outputted at the specified line number. But what if the line is pointing to the first line in the current file, and there is nothing visible, well the culprit may be a windows based editing software which converted the php file into UTF-8.

So the file encoding may destroy the php script. Changin the encoding back to ANSI would clear the problem.

Categories: Code Snippets Tags:

WordTwit – just finished integrating to a couple of my wordpress sites

July 19th, 2009 No comments

I have just finished integrating wordtwit to as well as this blog. There is nothing much to hoot and howl about it, other than I just made some tweaks here and there. One being the addition of auto hash tagging for twitter with the help of tag the net. And another one to replace the url compression with a similar service which I started just on a fancy, also I replaced those since I was not interested in retaining the included small url options.

While working for the auto hash tagging, I found that the function twit_hit_server, near about line 215, was not updating the $output variable, with the results in case the method was post, so I just added that $output = $snoopy->results; to the conditions inside if ($post) / if ($result).

Then changed

$message = str_replace( '[title]', get_the_title(), $message );


$message = str_replace( '[title]', wordtwit_tagify_title(get_the_title()), $message );

inside the function post_now_published definition.

The code listing for wordtwit_tagify_title is

function wordtwit_tagify_title($text){
$output '';
strlen($text) > 110$text substr($text0100) . ' ...';
twit_hit_server''''''$outputtrue, array( 'text' => $text'view' => 'json' ) );
$res = @json_decode($output);
$topTag $res->memes[0]->dimensions->topic[0];
$g strpos($text$topTag);
substr($text0$g) . '#' substr($text$g);

WordTwit is a plugin that utilizes the Twitter API to automatically push a published post to your Twitter account as a tweet. It allows all your Twitter contacts to keep up to date with your blog postings.

Categories: Code Snippets Tags: