Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Regex is an overkill in this case.</p> <p><strong>From the <a href="http://php.net/urlencode" rel="nofollow">urlencode manual</a>:</strong></p> <blockquote> <p>Returns a string in which all non-alphanumeric characters except <code>-_.</code> have been replaced with a percent (<code>%</code>) sign followed by two hex digits and spaces encoded as plus (<code>+</code>) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. This differs from the <a href="http://www.faqs.org/rfcs/rfc3986" rel="nofollow">» RFC 3986</a> encoding (<strong>see <a href="http://php.net/rawurlencode" rel="nofollow"><code>rawurlencode()</code></a>) in that for historical reasons, spaces are encoded as plus (<code>+</code>) signs</strong>.</p> </blockquote> <p>It clearly states that if you want spaces to be encoded as <code>%20</code>, and not <code>+</code>, you should use <a href="http://php.net/rawurlencode" rel="nofollow"><code>rawurlencode()</code></a>.</p> <p><strong>Code example:</strong></p> <p> <pre><code>$strings = array( '36 2543541284', '1234 5678', 'this is a string' ); $strings_encoded = array(); foreach($strings as $string) { $strings_encoded[] = rawurlencode($string); } var_dump($strings_encoded); </code></pre> <p><strong>Outputs:</strong></p> <pre><code>array(3) { [0]=&gt; string(15) "36%202543541284" [1]=&gt; string(11) "1234%205678" [2]=&gt; string(22) "this%20is%20a%20string" } </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