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

[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 ??
#2

[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.
#3

[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.
#4

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

[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.
#6

[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);
}
#7

[eluser]Sumon[/eluser]
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