Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't my url encoding working?
    text
    copied!<p>Please forgive me if this question appears too cheap. </p> <p>I have this line:</p> <pre><code>preg_match_all($pattern, $_GET['id'], $arr); </code></pre> <p>When you pass a value with space during a search, the value breaks once a space is encountered.</p> <p>For instance:</p> <pre><code>36 2543541284 </code></pre> <p>Notice a space between 6 and 2. In a situation similar to this, only 36 is displayed.</p> <p>The reminder of digits after space are ignored. This is giving users, "no data found" message.</p> <p>I have tried using urlencode to add 20% but no luck.</p> <pre><code>preg_match_all($pattern, rawurlencode($_GET[id]), $arr); </code></pre> <p>I have also tried urlencode but to no avail.</p> <p>What am I possibly doing wrong?</p> <pre><code>function format($matches) { return $matches[1][0].(strlen($matches[2][0])&gt;0?$matches[2][0]:" ").$matches[3][0].(strlen($matches[4][0])&gt;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 '&lt;pre&gt;' . 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; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload