ob_start() is partially capturing data

Posted by AAA on Stack Overflow See other posts from Stack Overflow or by AAA
Published on 2010-12-28T17:52:20Z Indexed on 2010/12/28 17:53 UTC
Read the original article Hit count: 290

Filed under:
|
|
|
|

I am using the following code:

PHP:

// Generate Guid function NewGuid() { $s = strtoupper(uniqid(rand(),true)); $guidText = substr($s,0,8) . '-' . substr($s,8,4) . '-' . substr($s,12,4). '-' . substr($s,16,4). '-' . substr($s,20); return $guidText; } // End Generate Guid

$Guid = NewGuid();

$alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';

function base_encode($num, $alphabet) { $base_count = strlen($alphabet); $encoded = '';

while ($num >= $base_count) {

    $div = $num/$base_count;
    $mod = ($num-($base_count*intval($div)));
    $encoded = $alphabet[$mod] . $encoded;
    $num = intval($div);
}

if ($num) $encoded = $alphabet[$num] . $encoded;
    return $encoded;

}

function base_decode($num, $alphabet) { $decoded = 0; $multi = 1;

while (strlen($num) > 0) {
    $digit = $num[strlen($num)-1];
    $decoded += $multi * strpos($alphabet, $digit);
    $multi = $multi * strlen($alphabet);
    $num = substr($num, 0, -1);
}

return $decoded;

}

ob_start(); echo base_encode($Guid, $alphabet); //should output: bUKpk $theid = ob_get_contents(); ob_get_clean();

The problem:

When i echo $theid, it shows the complete entry, but as it is being inserted into the database, only the first entry in the sequence gets inserted, for example for the entry buKPK, only 'b' is being inserted not the rest.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql