この質問が安っぽく見える場合は、ご容赦ください。
私はこの行を持っています:
preg_match_all($pattern, $_GET['id'], $arr);
検索中にスペースを含む値を渡すと、スペースが検出されると値が壊れます。
例えば:
36 2543541284
6 と 2 の間にスペースがあることに注意してください。このような状況では、36 だけが表示されます。
スペースの後の数字のリマインダーは無視されます。これにより、ユーザーに「データが見つかりません」というメッセージが表示されます。
urlencode を使用して 20% を追加しようとしましたが、うまくいきませんでした。
preg_match_all($pattern, rawurlencode($_GET[id]), $arr);
urlencode も試しましたが、役に立ちませんでした。
私は間違っている可能性がありますか?
function format($matches)
{
return $matches[1][0].(strlen($matches[2][0])>0?$matches[2][0]:" ").$matches[3][0].(strlen($matches[4][0])>0?" ".$matches[4][0]:"");
}
// CONSTRUCT A REGULAR EXPRESSION
$pattern
= '/' // regex delimiter
. '(' // START of a capture group
. '\d{2}' // exactly two digits
. ')' // END of capture group
. '(' // START SECOND capture group
. '[ND]?' // letters "D" OR "N" in any order or number - This is optional
. ')' // END SECOND capture group
. '(' // START THIRD capture group
. '\d*' // any number of digits
. ')' // END THIRD capture group
. '(' // START FOURTH capture group
. 'GG' // the letters "GG" EXACTLY
. '[\d]*' // any number of digits
. ')' // END THIRD capture group
. '?' // make the LAST capture group OPTIONAL
. '/' // regex delimiter
;
preg_match_all($pattern, rawurlencode($_GET[id]), $arr);
// REFORMAT the array
$str = format($arr);
// show what we did to the data
echo '<pre>' . PHP_EOL;
echo '1...5...10...15...20...' . PHP_EOL;
echo $pattern;
echo PHP_EOL;
//Are we getting what we asked for? This is a test. We will comment out all 6 lines if we are happy with output of our REFORMATTING.
echo $str;
echo PHP_EOL;