kalle Thu Aug 14 02:55:14 2008 UTC Modified files: /php-src/ext/standard basic_functions.c string.c Log: Implemented feature request #34381 (nl2br() should have an option for XHTML/HTML compatible BR element) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.913&r2=1.914&diff_format=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.913 php-src/ext/standard/basic_functions.c:1.914 --- php-src/ext/standard/basic_functions.c:1.913 Thu Aug 7 09:24:04 2008 +++ php-src/ext/standard/basic_functions.c Thu Aug 14 02:55:13 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.913 2008/08/07 09:24:04 lbarnaud Exp $ */ +/* $Id: basic_functions.c,v 1.914 2008/08/14 02:55:13 kalle Exp $ */ #include "php.h" #include "php_streams.h" @@ -2742,6 +2742,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.678&r2=1.679&diff_format=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.678 php-src/ext/standard/string.c:1.679 --- php-src/ext/standard/string.c:1.678 Tue Jul 29 16:51:21 2008 +++ php-src/ext/standard/string.c Thu Aug 14 02:55:13 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.678 2008/07/29 16:51:21 felipe Exp $ */ +/* $Id: string.c,v 1.679 2008/08/14 02:55:13 kalle Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -5978,19 +5978,20 @@ } /* }}} */ -/* {{{ proto string nl2br(string str) U +/* {{{ proto string nl2br(string str [, bool is_xhtml]) U Converts newlines to HTML line breaks */ PHP_FUNCTION(nl2br) { - /* in brief this inserts <br /> before matched regexp \n\r?|\r\n? */ - zstr str; - int str_len; - zend_uchar str_type; - zstr p, end, tmp, target; + /* in brief this inserts <br /> or <br> before matched regexp \n\r?|\r\n? */ + zstr str; + int str_len; + zend_uchar str_type; + zstr p, end, tmp, target; int new_length; int repl_cnt = 0; + zend_bool is_xhtml = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &str, &str_len, &str_type) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|b", &str, &str_len, &str_type, &is_xhtml) == FAILURE) { return; } @@ -6038,7 +6039,11 @@ RETURN_ZSTRL(str_type, 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); + } if (str_type == IS_UNICODE) { tmp.u = target.u = eumalloc(new_length + 1); @@ -6051,8 +6056,12 @@ *target.u++ = (UChar) 0x3c /*'<'*/; *target.u++ = (UChar) 0x62 /*'b'*/; *target.u++ = (UChar) 0x72 /*'r'*/; - *target.u++ = (UChar) 0x20 /*' '*/; - *target.u++ = (UChar) 0x2f /*'/'*/; + + if (is_xhtml) { + *target.u++ = (UChar) 0x20 /*' '*/; + *target.u++ = (UChar) 0x2f /*'/'*/; + } + *target.u++ = (UChar) 0x3e /*'>'*/; if ((*p.u == (UChar) 0x0d /*'\r'*/ && *(p.u+1) == (UChar) 0x0a /*'\n'*/) @@ -6079,8 +6088,12 @@ *target.s++ = '<'; *target.s++ = 'b'; *target.s++ = 'r'; - *target.s++ = ' '; - *target.s++ = '/'; + + if (is_xhtml) { + *target.s++ = ' '; + *target.s++ = '/'; + } + *target.s++ = '>'; if ((*p.s == '\r' && *(p.s+1) == '\n') || (*p.s == '\n' && *(p.s+1) == '\r')) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php