kalle Thu Aug 14 02:56:23 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src NEWS
/php-src/ext/standard basic_functions.c string.c
Log:
MFH: Implemented feature request #34381 (nl2br() should have an option for
XHTML/HTML compatible BR element)
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.266&r2=1.2027.2.547.2.965.2.267&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.266
php-src/NEWS:1.2027.2.547.2.965.2.267
--- php-src/NEWS:1.2027.2.547.2.965.2.266 Wed Aug 13 11:20:25 2008
+++ php-src/NEWS Thu Aug 14 02:56:22 2008
@@ -12,6 +12,9 @@
- Added litespeed SAPI module. (George Wang)
- Added ext/hash support to ext/session's ID generator. (Sara)
+- Implemented feature request #34381 (nl2br() should have an option for
+ XHTML/HTML compatible BR element) (Kalle)
+
- Fixed a bug causing miscalculations with the "last <weekday> of <n> month"
relative time string. (Derick)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.64.2.46&r2=1.725.2.31.2.64.2.47&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.46
php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.47
--- php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.46 Thu Aug 7
09:25:32 2008
+++ php-src/ext/standard/basic_functions.c Thu Aug 14 02:56:22 2008
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.46 2008/08/07 09:25:32 lbarnaud
Exp $ */
+/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.47 2008/08/14 02:56:22 kalle Exp
$ */
#include "php.h"
#include "php_streams.h"
@@ -2739,6 +2739,7 @@
static
ZEND_BEGIN_ARG_INFO(arginfo_nl2br, 0)
ZEND_ARG_INFO(0, str)
+ ZEND_ARG_INFO(0, is_xhtml)
ZEND_END_ARG_INFO()
static
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.445.2.14.2.69.2.33&r2=1.445.2.14.2.69.2.34&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.445.2.14.2.69.2.33
php-src/ext/standard/string.c:1.445.2.14.2.69.2.34
--- php-src/ext/standard/string.c:1.445.2.14.2.69.2.33 Thu Jul 31 14:20:40 2008
+++ php-src/ext/standard/string.c Thu Aug 14 02:56:23 2008
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.445.2.14.2.69.2.33 2008/07/31 14:20:40 ohill Exp $ */
+/* $Id: string.c,v 1.445.2.14.2.69.2.34 2008/08/14 02:56:23 kalle Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -3887,18 +3887,19 @@
}
/* }}} */
-/* {{{ proto string nl2br(string str)
+/* {{{ proto string nl2br(string str [, bool is_xhtml])
Converts newlines to HTML line breaks */
PHP_FUNCTION(nl2br)
{
- /* in brief this inserts <br /> before matched regexp \n\r?|\r\n? */
- char *tmp, *str;
- int new_length;
- char *end, *target;
- int repl_cnt = 0;
- int str_len;
+ /* in brief this inserts <br /> or <br> before matched regexp
\n\r?|\r\n? */
+ char *tmp, *str;
+ int new_length;
+ char *end, *target;
+ int repl_cnt = 0;
+ int str_len;
+ zend_bool is_xhtml = 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|b", &str,
&str_len, &is_xhtml) == FAILURE) {
return;
}
@@ -3927,7 +3928,12 @@
RETURN_STRINGL(str, str_len, 1);
}
- new_length = str_len + repl_cnt * (sizeof("<br />") - 1);
+ if (is_xhtml) {
+ new_length = str_len + repl_cnt * (sizeof("<br />") - 1);
+ } else {
+ new_length = str_len + repl_cnt * (sizeof("<br>") - 1);
+ }
+
tmp = target = emalloc(new_length + 1);
while (str < end) {
@@ -3937,8 +3943,12 @@
*target++ = '<';
*target++ = 'b';
*target++ = 'r';
- *target++ = ' ';
- *target++ = '/';
+
+ if (is_xhtml) {
+ *target++ = ' ';
+ *target++ = '/';
+ }
+
*target++ = '>';
if ((*str == '\r' && *(str+1) == '\n') || (*str
== '\n' && *(str+1) == '\r')) {
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php