Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

html_break_long_words()

Description

HTML aware function to break up long words onto multiple lines for
PDF generation where CSS text wrapping can't be used

Parameters

ColumnTypeDefaultDescription
$html string HTML/text to be processed
$length: int
$matches; ''; foreach $matches[0] as $part
$length int Maximum word length

Return

string *

Location

include/render_functions.php lines 6218 to 6244

Definition

 
function html_break_long_words(string $htmlint $length): string {
    
    
// Regex to match tags and text separately
    
preg_match_all('/<[^>]+>|[^<]+/'$html$matches);

    
$output '';

    foreach (
$matches[0] as $part) {
        if (
$part[0] === '<') {
            
// If it's an HTML tag, add it to the output as-is
            
$output .= $part;
        } else {
            
// If it's plain text, process it for long words
            
$words preg_split('/(\s+)/'$part, -1PREG_SPLIT_DELIM_CAPTURE);

            foreach (
$words as $word) {
                if (
strlen($word) > $length) {
                    
// Insert <br> tags between chunks only
                    
$word wordwrap($word$length'<br>'true);
                }
                
$output .= $word;
            }
        }
    }

    return 
$output;
}

This article was last updated 30th March 2026 18:05 Europe/London time based on the source file dated 30th March 2026 17:05 Europe/London time.