Skip to content

Commit 60d1f1d

Browse files
committedMar 14, 2015
New API function: http_build_url()
Builds an URL from its components. This is basically the reverse of parse_url(), a minimalistic implementation of pecl_http extension's http_build_url() function [1]. Note: the function is wrapped in an if function exists block, so that we use the extension's function if it is enabled. [1] http://php.net/http-build-url
1 parent c2005d8 commit 60d1f1d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 

‎core/http_api.php

+24
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,27 @@ function http_all_headers() {
187187
http_custom_headers();
188188
}
189189
}
190+
191+
if( !function_exists( 'http_build_url' ) ) {
192+
/**
193+
* Builds an URL from its components
194+
* This is basically the reverse of parse_url(), a minimalistic implementation
195+
* of pecl_http extension's http_build_url() function.
196+
* @param array $p_url The URL components (as results from parse_url())
197+
* @return string
198+
*/
199+
function http_build_url( array $p_url ) {
200+
return
201+
( isset( $p_url['scheme'] ) ? $p_url['scheme'] . '://' : '' )
202+
. ( isset( $p_url['user'] )
203+
? $p_url['user'] . ( isset( $p_url['pass'] ) ? ':' . $p_url['pass'] : '' ) .'@'
204+
: ''
205+
)
206+
. ( isset( $p_url['host'] ) ? $p_url['host'] : '' )
207+
. ( isset( $p_url['port'] ) ? ':' . $p_url['port'] : '' )
208+
. ( isset( $p_url['path'] ) ? $p_url['path'] : '' )
209+
. ( isset( $p_url['query'] ) ? '?' . $p_url['query'] : '' )
210+
. ( isset( $p_url['fragment'] ) ? '#' . $p_url['fragment'] : '' )
211+
;
212+
}
213+
}

0 commit comments

Comments
 (0)
Please sign in to comment.