urlencode_deep()
Navigates through an array, object, or scalar, and encodes the values to be used in a URL.
Uses: map_deep()
1 time — 0.000011 sec (very fast) | 50000 times — 0.02 sec (speed of light) | PHP 7.0.8, WP 4.6.1
No Hooks.
Return
Mixed
. The encoded value.
Usage
urlencode_deep( $value );
- $value(mixed) (required)
- The array or string to be encoded.
Examples
#1 Examples of URL encoding in an array
$arr = array( 'url' => 'http://example.com/one', 'url2' => 'http://example.com/two', 'url_arr' => array( 'url' => 'http://example.com/three', ), ); $arr = urlencode_deep( $arr ); print_r( $arr ); /* We get: Array ( [url] => http%3A%2F%2Fexample.com%2Fone [url2] => http%3A%2F%2Fexample.com%2Ftwo [url_arr] => Array ( [url] => http%3A%2F%2Fexample.com%2Fthree ) ) */
#2 It can also be used instead of urlencode()
echo urlencode_deep( 'http://example.com/one' ); // http%3A%2F%2Fexample.com%2Fone echo urlencode( 'http://example.com/one' ); // http%3A%2F%2Fexample.com%2Fone
Changelog
Since 2.2.0 | Introduced. |
urlencode_deep() urlencode deep code WP 6.6.2
function urlencode_deep( $value ) { return map_deep( $value, 'urlencode' ); }