0 votes
in SoSci Survey (English) by s139401 (110 points)
closed by SoSci Survey

I've built a two PHP functions that convert the answers to my questionnaire into a non-human readable format Octal-blocks -> Base-32.

However the PHP editor tells me that I cannot run base_convert and str_split. Is there a way around this?

 function str_baseconvert($str, $frombase=10, $tobase=36) {
    $str = trim($str);
    if (intval($frombase) != 10) {
        $len = strlen($str);
        $q = 0;
        for ($i=0; $i<$len; $i++) {
            $r = base_convert($str[$i], $frombase, 10);
            $q = bcadd(bcmul($q, $frombase), $r);
        }
    }
    else $q = $str;

    if (intval($tobase) != 10) {
        $s = '';
        while (bccomp($q, '0', 0) > 0) {
            $r = intval(bcmod($q, $tobase));
            $s = base_convert($r, 10, $tobase) . $s;
            $q = bcdiv($q, $tobase, 0);
        }
    }
    else $s = $q;

    return $s;
}

function base_5char($base8){
    $base32= [];
    $base8 = str_split($base8, 5);
    foreach($base8 as $key => $value){
        $base32[$key] = str_baseconvert($value, 8, 32);
        if(strlen($base32[$key])==2){
            $base32[$key] = "0".$base32[$key];
        }
        elseif(strlen($base32[$key])==1){
            $base32[$key] = "00".$base32[$key];
        }
    }
    return implode($base32);
}
closed with the note: As there are no more answers, I assume that the functions are not really necessary.
by SoSci Survey (328k points)
May I kindly ask for the goal of "recoding" the answer? This seems no everyday task in a survey :)
by s139401 (110 points)
Thank you very much for your quick answer! I would gladly rewrite the code to only include PHP-functions listed, however it would be close to impossible.

I can get around the use of str_split by using the available preg_split, however building a base convertor without the function base_convert and with only the allowed functions will be very difficult.
by SoSci Survey (328k points)
I am still interesed in what you goal is, you wish to achieve. What do you do with the data after recoding them?

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...