CoderZone.org

Category: >> PHP Code >> Smart Word Wrap Function Bookmark and Share

<< lastnext >>

Snippet Name: Smart Word Wrap Function

Description: This function will break up strings that don't have whitespace characters in them. If the $forcecut parameter is 'true' the strings will be broken whether or not there are whitespace chars.

Also see:
» Easy Password Encryption and Decry...
» Write or update an htpasswd file i...
» One-liner to swap variables
» Remove empty lines from a string o...
» Easy way to break apart an email a...
» Word-Unwrap Function
» Remove empty lines from text files
» Multi-line variables and strings i...
» Users Online in ASP
» Create an array from the lines of ...
» Remove Duplicate Lines from a File
» Distance Calculation using Latitud...
» A One-liner To Get Module Version
» Confiurable "Wrap Lines" Function
» Convert Dollars And Cents Value to...
» Check whether a date belongs to a ...
» Neatly trim a string to a set numb...
» Simple one-line template engine
» Remove Duplicate Lines from a File
» Inline search and replace
» Convert LONGs to LOBs
» Yahoo Online Status
» Online PHP Tester
» Display html source with line numb...
» Truncate Links Over X Chars long
» Remove extra linebreaks
» Prompt user at command line
» AJAX Inline Editor #1
» AJAX Inline Editor #2

Comment: (none)

Author:
Language: PHP
Highlight Mode: PHP
Last Modified: December 16th, 2010

// function to break up strings without whitespace chars in between
// if $forcecut is true then strings will be forcefully broken even there 
// are whitespace chars in between.
 
function unicode_wordwrap($str, $len=30, $break=" ", $forcecut=true){
    if(empty($str)) return "";
 
    $pattern="";
    if(!$forcecut)
        $pattern="/(\S{".$len."})/u";
    else
        $pattern="/(.{".$len."})/u";
 
    return preg_replace($pattern, "\${1}".$break, $str);
} 
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 7