Discussion:
wordwrap
Negin Nickparsa
2014-08-03 23:10:12 UTC
Permalink
I am learning string functions in php, I couldn't understand wordwrap
although I read first examples.

I have this example in the book:
$text = "able osts indy";
$newtext = wordwrap($text, 1, "c",false);

echo $newtext;

result is ablecostscindy

I understand that by adding </br> or </n> we are breaking the string every
with number so is the able the zerost word and the osts first word and so c
is added there or what? I need to clarify this in my mind. thank you.

Sincerely
Negin Nickparsa
Aziz Saleh
2014-08-03 23:15:47 UTC
Permalink
Post by Negin Nickparsa
I am learning string functions in php, I couldn't understand wordwrap
although I read first examples.
$text = "able osts indy";
$newtext = wordwrap($text, 1, "c",false);
echo $newtext;
result is ablecostscindy
I understand that by adding </br> or </n> we are breaking the string every
with number so is the able the zerost word and the osts first word and so c
is added there or what? I need to clarify this in my mind. thank you.
Sincerely
Negin Nickparsa
It all bottles to that fourth param (you have it set to false). If it is
set to false, it will keep words intact and wrap (based on the third
param). If set to true, it will cut the words. So in your example, if your
fourth param was true you would've had:

acbclcecocsctcscicncdcy

As you can see the wrapper is inserted every x positions (where x is the
second param).
Negin Nickparsa
2014-08-03 23:21:08 UTC
Permalink
​again I cannot understand in case of false what's happening ​"able osts
indy"; the able is first word the osts is second and indy is the third one
yes? so if we keep it intact why we don't have cablecostscindy? and we have
instead ablecostscindy? and how it understands to just replace the space
characters with the c char?


Sincerely
Negin Nickparsa
Post by Aziz Saleh
Post by Negin Nickparsa
I am learning string functions in php, I couldn't understand wordwrap
although I read first examples.
$text = "able osts indy";
$newtext = wordwrap($text, 1, "c",false);
echo $newtext;
result is ablecostscindy
I understand that by adding </br> or </n> we are breaking the string every
with number so is the able the zerost word and the osts first word and so c
is added there or what? I need to clarify this in my mind. thank you.
Sincerely
Negin Nickparsa
It all bottles to that fourth param (you have it set to false). If it is
set to false, it will keep words intact and wrap (based on the third
param). If set to true, it will cut the words. So in your example, if your
acbclcecocsctcscicncdcy
As you can see the wrapper is inserted every x positions (where x is the
second param).
Aziz Saleh
2014-08-03 23:39:35 UTC
Permalink
Post by Negin Nickparsa
​again I cannot understand in case of false what's happening ​"able osts
indy"; the able is first word the osts is second and indy is the third one
yes? so if we keep it intact why we don't have cablecostscindy? and we have
instead ablecostscindy? and how it understands to just replace the space
characters with the c char?
Sincerely
Negin Nickparsa
Post by Aziz Saleh
Post by Negin Nickparsa
I am learning string functions in php, I couldn't understand wordwrap
although I read first examples.
$text = "able osts indy";
$newtext = wordwrap($text, 1, "c",false);
echo $newtext;
result is ablecostscindy
I understand that by adding </br> or </n> we are breaking the string every
with number so is the able the zerost word and the osts first word and so c
is added there or what? I need to clarify this in my mind. thank you.
Sincerely
Negin Nickparsa
It all bottles to that fourth param (you have it set to false). If it is
set to false, it will keep words intact and wrap (based on the third
param). If set to true, it will cut the words. So in your example, if your
acbclcecocsctcscicncdcy
As you can see the wrapper is inserted every x positions (where x is the
second param).
Wordwrap wraps space characters based on spaces (if 4th param is false) or
to any character (if 4th param is true).

Wordwrap starts as position 0, then goes on to the space character (if 4th
param is false) or the X (2nd param) position and inserts what you
specified in. The last character doesn't need to be wrapped.
Negin Nickparsa
2014-08-03 23:48:11 UTC
Permalink
now I understand better,thank you for clarification.


Sincerely
Negin Nickparsa
Post by Aziz Saleh
Post by Negin Nickparsa
​again I cannot understand in case of false what's happening ​"able osts
indy"; the able is first word the osts is second and indy is the third one
yes? so if we keep it intact why we don't have cablecostscindy? and we have
instead ablecostscindy? and how it understands to just replace the space
characters with the c char?
Sincerely
Negin Nickparsa
Post by Aziz Saleh
Post by Negin Nickparsa
I am learning string functions in php, I couldn't understand wordwrap
although I read first examples.
$text = "able osts indy";
$newtext = wordwrap($text, 1, "c",false);
echo $newtext;
result is ablecostscindy
I understand that by adding </br> or </n> we are breaking the string every
with number so is the able the zerost word and the osts first word and so c
is added there or what? I need to clarify this in my mind. thank you.
Sincerely
Negin Nickparsa
It all bottles to that fourth param (you have it set to false). If it is
set to false, it will keep words intact and wrap (based on the third
param). If set to true, it will cut the words. So in your example, if your
acbclcecocsctcscicncdcy
As you can see the wrapper is inserted every x positions (where x is the
second param).
Wordwrap wraps space characters based on spaces (if 4th param is false) or
to any character (if 4th param is true).
Wordwrap starts as position 0, then goes on to the space character (if 4th
param is false) or the X (2nd param) position and inserts what you
specified in. The last character doesn't need to be wrapped.
Loading...