Re: [PHP-DEV] Fix for wordwrap()

2003-03-08 Thread Tom Sommer
On Fri, 7 Mar 2003 08:20:19 +0100, Jedi/Sector One wrote:

 $a = w\nphprules\nw;
 print wordwrap($a, 10, 'br /', 10);

   Output :
   
 wwbr /wwbr /w
 phprbr /ules
 wbr /

It's not

it breaks with br / after 10 chars by force, because the cut argument is 
set

why have you set cut to 10?

as the documentation states, 
If the cut is set to 1, the string is always wrapped at the specified 
width. So if you have a word that is larger than the given width, it is 
broken apart.

wordwrap is not broken...

It can be discussed if the cutcount (10) should be reset after a \n... 
which would be logic?

PS. cut should had been a boolean, IMHO :)
-- 
Tom Sommer, denmark
www.tsn.dk - www.dreamcoder.dk

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Fix for wordwrap()

2003-03-08 Thread Derick Rethans
On Sun, 9 Mar 2003, Tom Sommer wrote:

 PS. cut should had been a boolean, IMHO :)

It is:

zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|lsb

(b = boolean)

Derick

-- 
my other box is your windows PC
-
 Derick Rethans http://derickrethans.nl/ 
 PHP Magazine - PHP Magazine for Professionals   http://php-mag.net/
-

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Fix for wordwrap()

2003-03-08 Thread Tom Sommer
On Sun, 9 Mar 2003 01:05:01 +0100 (CET), Derick Rethans wrote:

 It is:

 zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|lsb

 (b = boolean)

Ok, the documentation says it is an integer... (ofcause true == 1, but 
still)

-- 
Tom Sommer, denmark
www.tsn.dk - www.dreamcoder.dk

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Fix for wordwrap()

2003-03-08 Thread Derick Rethans
On Sun, 9 Mar 2003, Tom Sommer wrote:

 On Sun, 9 Mar 2003 01:05:01 +0100 (CET), Derick Rethans wrote:
 
  It is:
 
  zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|lsb
 
  (b = boolean)
 
 Ok, the documentation says it is an integer... (ofcause true == 1, but 
 still)

Docs were wrong, I just fixed that.

Derick

-- 
my other box is your windows PC
-
 Derick Rethans http://derickrethans.nl/ 
 PHP Magazine - PHP Magazine for Professionals   http://php-mag.net/
-

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Fix for wordwrap()

2003-03-08 Thread Tom Sommer
On Sun, 9 Mar 2003 01:07:53 +0100 (CET), Derick Rethans wrote:

 Docs were wrong, I just fixed that.
methodparam 
choice=opttypeboolean/typeparametercut/parameter/methodparam

should be

methodparam 
choice=opttypebool/typeparametercut/parameter/methodparam

since all other doc elements use bool and not boolan :)
Guess I am a perfectionist

-- 
Tom Sommer, denmark
www.tsn.dk - www.dreamcoder.dk

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Fix for wordwrap()

2003-03-08 Thread Tom Sommer
On Sun, 9 Mar 2003 01:07:53 +0100 (CET), Derick Rethans wrote:

 Docs were wrong, I just fixed that.

oh, and the examples and the text about cut needs to be changed to :)

If the parametercut/parameter is set to *1*

-- 
Tom Sommer, denmark
www.tsn.dk - www.dreamcoder.dk

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Fix for wordwrap()

2003-03-06 Thread Jedi/Sector One
  Hello.
  
  Maybe this is the intended behavior, but wordwrap()'s behavior is a bit
illogical on PHP 4.3.1, as it does only break after a plain whitespace, not
after punctuation, \n, etc.

  Here's a trivial sample :
  
$a = ww\nphprules\nw;
print wordwrap($a, 10, ' ', 10);

  Output :
  
ww 
p hprules
ww ww w

  The following trivial patch makes wordwrap() wrap after any
non-alphanumeric charater. Output after application of that patch :

ww  phprules ww www

  Best regards,
  
   -Frank.
--- php-4.3.1/ext/standard/string.c 2002-12-27 04:22:20.0 +0100
+++ php-4.3.1-jedi/ext/standard/string.c2003-03-06 12:41:46.0 +0100
@@ -654,7 +654,7 @@
for (current = 0; current  textlen; current++) {
if (text[current] == breakchar[0]) {
laststart = lastspace = current;
-   } else if (text[current] == ' ') {
+   } else if (!isalnum((unsigned char) text[current])) {
if (current - laststart = linelength) {
newtext[current] = breakchar[0];
laststart = current;
@@ -701,7 +701,7 @@
}
/* if it is a space, check if it is at the line boundary,
 * copy and insert a break, or just keep track of it */
-   else if (text[current] == ' ') {
+   else if (!isalnum((unsigned char) text[current])) {
if (current - laststart = linelength) {
memcpy(newtext+newtextlen, text+laststart, 
current-laststart);
newtextlen += current - laststart;

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] Fix for wordwrap()

2003-03-06 Thread Ilia A.
On March 6, 2003 06:52 am, Jedi/Sector One wrote:
   Hello.

   Maybe this is the intended behavior, but wordwrap()'s behavior is a bit
 illogical on PHP 4.3.1, as it does only break after a plain whitespace, not
 after punctuation, \n, etc.

   Here's a trivial sample :

 $a = ww\nphprules\nw;
 print wordwrap($a, 10, ' ', 10);

   Output :

 ww 
 p hprules
 ww ww w

   The following trivial patch makes wordwrap() wrap after any
 non-alphanumeric charater. Output after application of that patch :

 ww  phprules ww www

Seems like the expected behavior to me, you are hardcoding the 'break' as ' ', 
meaning that no other character is considered a space hence, \n are being 
treated as part of the string rather then a string separator.

Ilia

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Fix for wordwrap()

2003-03-06 Thread Jedi/Sector One
On Thu, Mar 06, 2003 at 09:53:22AM -0500, Ilia A. wrote:
 you are hardcoding the 'break' as ' ',
 meaning that no other character is considered a space hence

  The documentation states that 'break' is what is used to break lines, not
what is considered a space. 

  Simple try with PHP 4.3.1 :
  
$a = w\nphprules\nw;
print wordwrap($a, 10, 'br /', 10);

  Output :
  
wwbr /wwbr /w
phprbr /ules
wbr /

  Looks buggy to me.
  

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php