What function returns a new line if a string reaches

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

What function returns a new line if a string reaches

Post by impulse() »

A length defined as a parameter in the function?

Stephen,
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

:?: what?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I'm sure I came across a function a couple of weeks back that takes in a string and it inserts a "\n" character at specified points within the string.

For example

"If this was the string I wanted to use but I wanted PHP to return a new line every 20 characters into the string I could use the function to that just that.

So it would look like:

"If this was the stri
ng I wanted to use b
"
Etc etc.

Maybe I was dreaming about such function? :)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

The Ninja Space Goat wrote:http://us2.php.net/wordwrap
lol ohhh right! I was going to say

Code: Select all

function foo($string, $length) {
    if (strlen($string) >= $length) {
        return "\n";
    }
}
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Or chunk_split() if you need to split after X chars rather than at word boundaries.
Post Reply