Part of the EllisLab Network
   
 
word_wrap() bug??? 
Posted: 02 May 2008 07:06 AM   [ Ignore ]  
Summer Student
Total Posts:  2
Joined  05-02-2008

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
function

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

Profile
 
 
Posted: 02 May 2008 10:23 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  431
Joined  12-13-2007

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.

 Signature 

PX Webdesign | The Lab | Personal Blog

Profile
 
 
Posted: 29 May 2008 11:24 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  110
Joined  06-25-2007

So!!! We have no alternative of

wordwrap($text, 8, "\n", true);

I am very much hopeful, codeigniter will add this functionality very soon.

 Signature 

Bangaldesh Best Tourism Site [Going to be..]
http://www.shopno-dinga.com

Profile
 
 
Posted: 30 May 2008 05:54 AM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6492
Joined  03-23-2006

Sumon, you can absolutely use PHP in CodeIgniter.  If you want to use PHP’s native wordwrap() function, go for it!

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
 
 
Posted: 02 June 2008 11:53 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  110
Joined  06-25-2007

Yes that’s true and thanks for your kind feedback. but i shall be more happy if i get something like

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.

 Signature 

Bangaldesh Best Tourism Site [Going to be..]
http://www.shopno-dinga.com

Profile
 
 
Posted: 03 June 2008 12:06 AM   [ Ignore ]   [ # 5 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6492
Joined  03-23-2006

No problem.  Here you go.  Add this to system/application/helpers/text_helper.php

<?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);
}

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
 
 
Posted: 03 June 2008 01:21 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  110
Joined  06-25-2007

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

 Signature 

Bangaldesh Best Tourism Site [Going to be..]
http://www.shopno-dinga.com

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 60711 Total Logged-in Users: 16
Total Topics: 73164 Total Anonymous Users: 0
Total Replies: 394603 Total Guests: 380
Total Posts: 467767    
Members ( View Memberlist )