■背景
・phpを7.* から 8.* にアップデートしたら、urlencode()関数がエラーになったので、自作関数を作成し、一括置換して対応。
■エラーメッセージ
・Deprecated: urldecode(): Passing null to parameter #1 ($string) of type string is deprecated in C:************* .php on line 9999
■ 対応関数
function.php
// === PHP 8 対応 urlencode()
function UrlEncode_Val_Check($data)
{
if ($data != "") {
$data_encode = urlencode($data);
return $data_encode;
} else {
return $data = "";
}
}
■ 使い方
urlencodeをUrlEncode_Val_Checkに置換するだけ
index.php
echo '<tr style="background: green;" data-href="./five.php?select_day=' . UrlEncode_Val_Check($select_day) .
'&souko_code=' . UrlEncode_Val_Check($select_souko_code) .
'&unsou_code=' . UrlEncode_Val_Check($select_unsou_code) .
'&unsou_name=' . UrlEncode_Val_Check($Picking_VAL['Unsou_name']) .
'&shipping_moto=' . UrlEncode_Val_Check($Picking_VAL['shipping_moto']) .
'&shipping_moto_name=' . UrlEncode_Val_Check($Picking_VAL['shipping_moto_name']) .
'&Shouhin_code=' . UrlEncode_Val_Check($Picking_VAL['Shouhin_code']) .
'&Shouhin_name=' . UrlEncode_Val_Check($Picking_VAL['Shouhin_name']) .
'&Shouhin_num=' . UrlEncode_Val_Check($Picking_VAL['Shouhin_num']) .
'&Tokuisaki=' . UrlEncode_Val_Check($Tokuisaki_name) .
'&tana_num=' . UrlEncode_Val_Check($Picking_VAL['Tana_num']) .
'&case_num=' . UrlEncode_Val_Check($Case_num_View) .
'&bara_num=' . UrlEncode_Val_Check($Bara_num_View) .
'&shouhin_jan=' . UrlEncode_Val_Check($shouhin_JAN) .
'&tokki_zikou=' . $Picking_VAL['tokki_zikou'] .
'&Denpyou_SEQ=' . UrlEncode_Val_Check($Picking_VAL['Denpyou_SEQ']) . // 伝票 SEQ
'&now_sql=' . $encoded_sql_one_tokki . '">';