簡體   English   中英

如果文本代碼超過100,如何添加二維碼圖像

[英]how to add a qr code image if the text code is more than 100

如果文本代碼$result['data']['checkout_url']超過 100,如何添加二維碼圖像

圖片源代碼

<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl=<?= $result['data']['checkout_url']; ?>" width="200">

要編輯的代碼

if (filter_var($result['data']['checkout_url'], FILTER_VALIDATE_URL)) {
                        return redirect()->to($result['data']['checkout_url']);
                    } else {
                        $this->session->setFlashdata('success', 'Silahkan transfer sebesar Rp ' . number_format($data_post['quantity'],0,',','.') . ' ke ' . $result['data']['checkout_url'] . ' melalui ' . $data_method[0]['name'] . ' sebelum 1x24 jam.');
                        return redirect()->to(str_replace('index.php/', '', site_url(uri_string())));
                    }
                } else {
                    $this->session->setFlashdata('error', $result['message']);
                    return redirect()->to(str_replace('index.php/', '', site_url(uri_string())));
                }
            }
$chl = isset($_GET['chl']) ? $_GET['chl'] : ''; //Get the value of chl from the img

if(!empty($chl))             // If its not empty
{
$chl_length = strlen($chl);  //Get the length of the string - example 35

if($chl_length > 100) {      //If the str length is longer the 100 chars
//DO this
}
else {
//Do something else
}
else {
echo "Error: chl is empty"; 
}
 

進一步了解PHP strlen

它實際上可以超過 100 個字符。

Just Example with more than 100 chars: https://chart.googleapis.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl=aksjdnaksjdnajkdnaskjdasjkdnasjkdnkjasndkjasndkjasndjkaskdnjasnjdasndkjajsdnjkasdnasjndjknasjkdnjasnjkdnasjkndjknaskjdnjkasndjknasjkdnjkasnjkdnasjkndjknkjndiqwwuduqndh128918eh9218hd9wnu9asnoaslndoasndiasjdu192e8h1892h9eh12h8e812bsunfnuiasnduasidnasidjajd98129e8129h129hd9821h89dh219hdh1289h9d812h

示例二維碼

問題是您不應該在chl查詢參數中設置原始 url 。

最好這樣做,使用urlencode() function

<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl=<?= urlencode($result['data']['checkout_url']); ?>" width="200">

掃描 qr 后,使用urldecode() function 再次將其更改為 raw url,然后再進行下一步。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM