Welcome Guest, Not a member yet? Register   Sign In
word_wrap() bug???

[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:

$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

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

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.

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

[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!

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

[eluser]Derek Allard[/eluser]
No problem. Here you go. Add this to system/application/helpers/text_helper.php
&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);

Excellent idea Smile Great. Really great thinking.... why i not think this way before..... anyway.. thanks a lot Smile

Theme © iAndrew 2016 - Forum software by © MyBB