//load 3to4 encoding first
$handle = @fopen("3to4.txt", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
$buffer = explode(',',$buffer);
$_3to4[$buffer[0]] = trim($buffer[1]);
}
if (!feof($handle)) {
die("Error: unexpected fgets() fail");
}
fclose($handle);
}
$sms_text = "##AQypz3ujYRvyyal*#IQE############wzv1##0F";
//Divide into groups of 4 bytes each
$dat = str_split($sms_text,4);
//loop through the bytes
foreach($dat as $d){
//convert into array and reverse
$b = array_reverse(str_split($d));
$flipped_3to4 .= implode($b)." ";
//convert each element into hex using 3to4
foreach($b as $a){
$hex_val = array_search($a,$_3to4);
if($hex_val >'' || $hex_val ==0){
$bin_str .= str_pad(base_convert($hex_val,'16','2'),6,"0",STR_PAD_LEFT);
}else{
$missing .= $a;
}
}
$hex_str = str_pad(base_convert($bin_str,'2','16'),6,"0",STR_PAD_LEFT);
$raw .= $hex_str;
//then flip back
$hex_ar = str_split($hex_str,2);
foreach($hex_ar as $h){
//reverse for least significant byte
$str .= strrev($h)." ";
}
$hex_str .= strrev($str);
//clear vars
$hex_str = '';
$bin_str = '';
$str = '';
}
echo $hex_str;
Kwanza kibisa cheki hiyo function yako inatakiwa iwe fopen badala yake umeandika @fopen!!!!
Kuna mradi ninaofanya na nahitajika kutumia SMS kubeba payload. Tatizo kama tujuavyo SMS huwa limit yake ni 161 characters hivyo siwezi nikasafirisha bytes za kutosha.
Sasa imenilazimu kutumia mfumo wa CODE3TO4 ambao unaniwezesha kupunguza kila byte inabeba 6 bits badala ya kawaida 8 bits. Kwa ufupi, ujumbe mmoja wa SMS ukiwa encoded na huu mfumo unakuwezesha kubeba payload kubwa ambayo haingewezekana.
Sasa tatizo langu lipo kwenye code, nimefaulu na kila kitu kimeenda sawa kwa muda, lakini ghafla na intermittently imekua iki-misbehave, unakuta payload niliyotegemea siyo yaani baada ya kuwa parsed, ilhali sijabadilisha chochote kwenye logics.
[/FONT]
<?php
$string = "I am a long string very long string just try to compress me and you will see how compressed I can get
I am a long string very long string just try to compress me and you will see how compressed I can get
I am a long string very long string just try to compress me and you will see how compressed I can get
I am a long string very long string just try to compress me and you will see how compressed I can get
";
echo "Length of Uncompressed String:".strlen($string);
$compressed = gzdeflate($string, 9);
echo '<br/>Length of Compressed String:'.strlen($compressed).'<br/>';
echo $compressed;
echo gzinflate(gzinflate($compressed));
?>
[FONT=Verdana]
Jaribu kukagua mahali panapo sumbua kwa kuweka print syntax. e.g
//loop through the bytes
foreach($dat as $d){
//convert into array and reverse
$b = array_reverse(str_split($d));
print $b;
Hii inaweza kukusaidia kujua kwanini inaleta results usizozitarajia
Huu mfumo wa CODE3TO4 sipo familiar nao, je is it a well known compression algorithm that has been well tested?
I hope I wont be going off topic if I suggest a solution that accomplishes something close to what you want:
Kuna inbuilt PHP library unaweza ukatumia kufanya compression kwa long strings (for short strings i just dont see its use it just adds additional headers and the string might actually be longer)
PHP: gzdeflate - Manual
Here is a simple usage of the library
I might try to play around with your code nione kama nitaweza to debug it.Code:<?php $string = "I am a long string very long string just try to compress me and you will see how compressed I can get I am a long string very long string just try to compress me and you will see how compressed I can get I am a long string very long string just try to compress me and you will see how compressed I can get I am a long string very long string just try to compress me and you will see how compressed I can get "; echo "Length of Uncompressed String:".strlen($string); $compressed = gzdeflate($string, 9); echo '<br/>Length of Compressed String:'.strlen($compressed).'<br/>'; echo $compressed; echo gzinflate(gzinflate($compressed)); ?>