第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如果包含 Unicode 字符,則無法在 JavaScript 中解碼 PHP 中的編碼字符串

如果包含 Unicode 字符,則無法在 JavaScript 中解碼 PHP 中的編碼字符串

手掌心 2021-06-21 15:10:42
我正在嘗試使用類似于 Rot13 的算法在 PHP 中對(duì)字符串進(jìn)行編碼,然后在 JavaScript 中對(duì)字符串進(jìn)行解碼并進(jìn)行搜索和替換。它適用于 ASCII 字符,但不適用于 Unicode。我弄亂了附加的代碼,但無法讓它工作。<?phpfunction strRot($str, $n) {    $len = mb_strlen($str);    $min = 0;    $max = 99999999;    $final = '';    for ($i = 0; $i < $len; $i++) {        $current = mb_ord($str[$i]);        $val = $current+$n;        if ($val >= $max) {            $val = $val - $max;        }        if ($val <= $min) {            $val = $val + $min;        }        $final .= mb_chr($val);    }    return $final;}?><!doctype html><html><head>    <!-- Required meta tags -->    <meta charset="utf-8">    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">    <!-- Bootstrap CSS -->    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">    <title>Hello, world!</title></head><body>    <h1>Hello, world!</h1>    <h2>ü and ?. 棕色的狐貍跳了起來.</h2>    <p>The Hello, world! expression will be replaced.</p>    <p>ü and ?. 棕色的狐貍跳了起來. Should be replaced too.</p>    <!-- Optional JavaScript -->    <!-- jQuery first, then Popper.js, then Bootstrap JS -->    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>一旦 JS 運(yùn)行,它應(yīng)該用解碼后的數(shù)據(jù) [索引][1] 替換數(shù)據(jù) [索引][0]。
查看完整描述

2 回答

?
Helenr

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超4個(gè)贊

我發(fā)現(xiàn)的一種解決方案:


var data = [

            ["Hello, world!", "<?php echo base64_encode(strRot(rawurlencode('I got replaced.'), 1000)); ?>"],

            ["ü and ?. 棕色的狐貍跳了起來.", "<?php echo base64_encode(strRot(rawurlencode('? before ü and 棕色的.'), 1000)); ?>"]

        ];


// Then, in replace():


decodeURIComponent(strRot(b64DecodeUnicode(data[index][1]), -1000))

這是有效的,因?yàn)樗谛D(zhuǎn)之前轉(zhuǎn)義了所有 unicode 字符。唯一的問題是,由于轉(zhuǎn)義,當(dāng)涉及到字符串的大小時(shí),它會(huì)增加一些開銷。


查看完整回答
反對(duì) 回復(fù) 2021-06-24
?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

(我沒有足夠的聲譽(yù)來發(fā)表評(píng)論,所以我求助于使用答案......)

不確定它是否有所不同,但在 HTML“h2”標(biāo)題中,您的 Unicode 表達(dá)式是...

ü an ?. 棕色的狐貍跳了起來.

...在數(shù)據(jù)[]中,它是...

ü and ?. 棕色的狐貍跳了起來.

假設(shè)“an”和“and”應(yīng)該是一樣的?


查看完整回答
反對(duì) 回復(fù) 2021-06-24
  • 2 回答
  • 0 關(guān)注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)