CodeIgniter Forums
word_wrap() bug??? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: word_wrap() bug??? (/showthread.php?tid=8039)



word_wrap() bug??? - El Forum - 05-02-2008

[eluser]Cristian Gilè[/eluser]
I'm trying to use word_wrap() function but the text is not wrapped.
I've used the example in the CI guide:

Code:
$string = "Here is a simple string of text that will help us demonstrate this function.";

echo word_wrap($string, 25);

// Would produce:

Here is a simple string
of text that will help
us demonstrate this
function

Can you explain that ??
Is it a potential candidate bug ??


word_wrap() bug??? - El Forum - 05-02-2008

[eluser]Lone[/eluser]
Without testing it myself I am guessing you are trying to produce the text when viewing through a browser.

If you goto view the source of the page you will see it most likely is word wrapped - but browsers only render a new line with a <br /> or <br> tag. This function from memory is built more in use for something like an email message body.


word_wrap() bug??? - El Forum - 05-29-2008

[eluser]Sumon[/eluser]
So!!! We have no alternative of
Code:
wordwrap($text, 8, "\n", true);
I am very much hopeful, codeigniter will add this functionality very soon.


word_wrap() bug??? - El Forum - 05-30-2008

[eluser]Derek Allard[/eluser]
Sumon, you can absolutely use PHP in CodeIgniter. If you want to use PHP's native wordwrap() function, go for it!


word_wrap() bug??? - El Forum - 06-02-2008

[eluser]Sumon[/eluser]
Yes that's true and thanks for your kind feedback. but i shall be more happy if i get something like
Code:
word_limiter()
of CI. word_limiter() is an excellent function and if we get similar function for word_wrap that should be more pleasant. However, thanks.


word_wrap() bug??? - El Forum - 06-02-2008

[eluser]Derek Allard[/eluser]
No problem. Here you go. Add this to system/application/helpers/text_helper.php
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function word_wrap($str, $width, $break = "\n", $cut = FALSE)
{
    return wordwrap($str, $width, $break, $cut);
}



word_wrap() bug??? - El Forum - 06-03-2008

[eluser]Sumon[/eluser]
Excellent idea Smile Great. Really great thinking.... why i not think this way before..... anyway.. thanks a lot Smile