cvs: php-src /ext/standard url.c
| From: | Ilia Alshanetsky | Date: | Tue, 09 Aug 2005 14:17:29 +0000 |
| Subject: | cvs: php-src /ext/standard url.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-33239@lists.php.net to get a copy of this message | ||
iliaa Tue Aug 9 10:17:29 2005 EDT
Modified files:
/php-src/ext/standard url.c
Log:
Added option to parse_url() to retrieve a particular URL component.
http://cvs.php.net/diff.php/php-src/ext/standard/url.c?r1=1.86&r2=1.87&ty=u
Index: php-src/ext/standard/url.c
diff -u php-src/ext/standard/url.c:1.86 php-src/ext/standard/url.c:1.87
--- php-src/ext/standard/url.c:1.86 Wed Aug 3 10:08:14 2005
+++ php-src/ext/standard/url.c Tue Aug 9 10:17:28 2005
@@ -15,7 +15,7 @@
| Author: Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: url.c,v 1.86 2005/08/03 14:08:14 sniper Exp $ */
+/* $Id: url.c,v 1.87 2005/08/09 14:17:28 iliaa Exp $ */
#include <stdlib.h>
#include <string.h>
@@ -327,15 +327,16 @@
}
/* }}} */
-/* {{{ proto array parse_url(string url)
+/* {{{ proto mixed parse_url(string url, [int url_component])
Parse a URL and return its components */
PHP_FUNCTION(parse_url)
{
char *str;
int str_len;
php_url *resource;
+ long key = -1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) ==
FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len,
&key) == FAILURE) {
return;
}
@@ -345,6 +346,39 @@
RETURN_FALSE;
}
+ if (key > -1) {
+ switch (key) {
+ case PHP_URL_SCHEME:
+ if (resource->scheme != NULL) RETVAL_STRING(resource->scheme, 1);
+ break;
+ case PHP_URL_HOST:
+ if (resource->host != NULL) RETVAL_STRING(resource->host, 1);
+ break;
+ case PHP_URL_PORT:
+ if (resource->port != 0) RETVAL_LONG(resource->port);
+ break;
+ case PHP_URL_USER:
+ if (resource->user != NULL) RETVAL_STRING(resource->user, 1);
+ break;
+ case PHP_URL_PASS:
+ if (resource->pass != NULL) RETVAL_STRING(resource->pass, 1);
+ break;
+ case PHP_URL_PATH:
+ if (resource->path != NULL) RETVAL_STRING(resource->path, 1);
+ break;
+ case PHP_URL_QUERY:
+ if (resource->query != NULL) RETVAL_STRING(resource->query, 1);
+ break;
+ case PHP_URL_FRAGMENT:
+ if (resource->fragment != NULL) RETVAL_STRING(resource->fragment, 1);
+ break;
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid url component identifier %ld.",
key);
+ RETVAL_FALSE;
+ }
+ goto done;
+ }
+
/* allocate an array for return */
array_init(return_value);
@@ -365,8 +399,8 @@
add_assoc_string(return_value, "query", resource->query, 1);
if (resource->fragment != NULL)
add_assoc_string(return_value, "fragment", resource->fragment, 1);
-
- php_url_free(resource);
+done:
+ php_url_free(resource);
}
/* }}} */