十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
$content?=?$_POST['data'];
成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括南豐網(wǎng)站建設(shè)、南豐網(wǎng)站制作、南豐網(wǎng)頁制作以及南豐網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,南豐網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到南豐省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
$fp?=?fopen('/tmp/newfile.bin','w');
fwrite($fp,$content);
以上例子是在data參數(shù)上傳二進(jìn)制,并保存到/tmp/newfile.bin中,解析json用json_decode,然后把二進(jìn)制的那個值賦給content就可以
整形轉(zhuǎn)化成?2二進(jìn)制?可以用??base_convert:
$str?=?0x8000;
echo?$str2?=?base_convert($str,?16,?2);
echo?'br';
echo?base_convert($str2,?2,?16);
[code]
字符串?文件等?可以考慮用?pack?和?unpack?轉(zhuǎn)化成二進(jìn)制
[code=PHP]
$file1?=?'F:/46.gif';???????????//隨便拷一個圖片作為測試用
$file2?=?'F:/test.txt';?????????//生成的二進(jìn)制流保存在這個文件里
$file3?=?'F:/47.gif';???????????//由二進(jìn)制流還原成的文件
$size?=?filesize($file1);
echo?'文件大小為:'.$size;
echo?"\nbr轉(zhuǎn)化為二進(jìn)制?...";
$content?=?file_get_contents($file1);
$content?=?bstr2bin($content);
$fp?=?fopen($file2,?'w');
fwrite($fp,?$content);
fclose($fp);
$size2?=?filesize($file2);
echo?'轉(zhuǎn)化成二進(jìn)制后文件大小為:'.$size2;
$content?=?bin2bstr($content);
$fp?=?fopen($file3,?'w');
fwrite($fp,?$content);
fclose($fp);
function?bin2bstr($input)
//?Convert?a?binary?expression?(e.g.,?"100111")?into?a?binary-string
{
if?(!is_string($input))?return?null;?//?Sanity?check
//?Pack?into?a?string
$input?=?str_split($input,?4);
$str?=?'';
foreach?($input?as?$v)
{
$str?.=?base_convert($v,?2,?16);
}
$str?=??pack('H*',?$str);
return?$str;
}
function?bstr2bin($input)
//?Binary?representation?of?a?binary-string
{
if?(!is_string($input))?return?null;?//?Sanity?check
//?Unpack?as?a?hexadecimal?string
$value?=?unpack('H*',?$input);
//?Output?binary?representation
$value?=?str_split($value[1],?1);
$bin?=?'';
foreach?($value?as?$v)
{
$b?=?str_pad(base_convert($v,?16,?2),?4,?'0',?STR_PAD_LEFT);
$bin?.=?$b;
}
return?$bin;
}
參考代碼:
?php
$file="images/login.png";
$content = $GLOBALS['HTTP_RAW_POST_DATA'];
if(empty($content)){
$content = file_get_contents('php://input');
}
$result = file_put_contents($file, $content, true);
var_dump($result);
?
當(dāng)字符串處理轉(zhuǎn)換就行
/**
* 將字符串轉(zhuǎn)換成二進(jìn)制
* @param type $str
* @return type
*/
function StrToBin($str){
//1.列出每個字符
$arr = preg_split('/(?!^)(?!$)/u', $str);
//2.unpack字符
foreach($arr as $v){
$temp = unpack('H*', $v); $v = base_convert($temp[1], 16, 2);
unset($temp);
}
return join(' ',$arr);
}
可以的。
可以用一個十進(jìn)制二進(jìn)制的函數(shù)decbin(),生成的是一個字符串,直接輸出即可
需要準(zhǔn)備的材料分別是:電腦、php編輯器、瀏覽器。
1、首先,打開php編輯器,新建php文件,例如:index.php。
2、以二進(jìn)制數(shù)1110101為例,在index.php中,輸入代碼:$a = 0b1110101;echo $a;。
3、瀏覽器運(yùn)行index.php頁面,此時會看到二進(jìn)制數(shù)1110101被成功表示,并以十進(jìn)制形式打印了出來。