note 124034 added to function.wordwrap

From: Date: Fri, 12 Jul 2019 13:38:26 +0000
Subject: note 124034 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-211551@lists.php.net to get a copy of this message
wordwrap() uses the break string as the line break detected, and the break inserted, so your text must be standardized to the line break you want in the wordwrap() output before using wordwrap, otherwise you will get line breaks inserted regardless of the location of existing line breaks in your text. <?php $linebreak = '<br/>' . PHP_EOL; $width = 5; $standardized = preg_replace('/\r?\n/',$linebreak, "abc abc abc\nabc abc abc\r\nabc abc abc"); echo 'Standardized EOL:', PHP_EOL, $standardized, PHP_EOL, PHP_EOL; // PHP_EOL for the command line, use '<br/>' for HTML. echo "Wrapped at $width:", PHP_EOL, wordwrap( $standardized, 7, $linebreak), PHP_EOL; ?> $ php -f test.php Standardized EOL: abc abc abc<br/> abc abc abc<br/> abc abc abc Wrapped at 5: abc abc<br/> abc<br/> abc abc<br/> abc<br/> abc abc<br/> abc ---- Server IP: 208.43.231.9 Probable Submitter: 82.199.157.34 (proxied: 72.80.99.61) ---- Manual Page -- http://php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/124034 Del: integrated -- https://master.php.net/note/delete/124034/integrated Del: useless -- https://master.php.net/note/delete/124034/useless Del: bad code -- https://master.php.net/note/delete/124034/bad+code Del: spam -- https://master.php.net/note/delete/124034/spam Del: non-english -- https://master.php.net/note/delete/124034/non-english Del: in docs -- https://master.php.net/note/delete/124034/in+docs Del: other reasons-- https://master.php.net/note/delete/124034 Reject -- https://master.php.net/note/reject/124034 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#211551) next »