Авторизация
 Регистрация   Войти   Забыли пароль? 

br_text_by_strlen() PHP-Функция для записи текста в столбик определённой ширины знаков

Обновлённый PHP-Fusion Bogatyr / Free CMS PHP-Fusion 7 Bogatyr / PHP-functions for text / br_text_by_strlen() PHP-Функция для записи текста в столбик определённой ширины знаков


 Russian

br_text_by_strlen() PHP-Function for writing text in a column of a certain width of characters

Обновлённый PHP-Fusion Bogatyr / Free CMS PHP-Fusion 7 Bogatyr / PHP-functions for text / br_text_by_strlen() PHP-Function for writing text in a column of a certain width of characters


 English

PHP

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\mail_bbcode_include.php on line 20

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\mail_bbcode_include.php on line 21

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\search_bbcode_include.php on line 39
PHP
  1. <?php
  2. // RU:
  3. // Функция для записи текста в столбик определённой ширины знаков (используется изредка для заголовков)
  4. // функция делит строку `$header` на несколько строк с помощью `<br>`,
  5. // если длина слова превышает `$in_line=20`.
  6. // Делит по пробелу и чёрточке.
  7. // Предполагается, что в тексте нигде не встречается  "(-|-=|=-|-)"
  8. // EN:
  9. // Function for writing text in a column of a certain width of characters (used occasionally for headings)
  10. // the function divides the string `$ header` into several lines using` <br> `,
  11. // if the length of the word exceeds $ in_line = 20.
  12. // Divide by space and dot.
  13. // It is assumed that the text does not occur anywhere "(-|-=|=-|-)"
  14. if (!function_exists("br_text_by_strlen")) {
  15. function br_text_by_strlen ($header, $in_line=20 , $exp = "(-|-=|=-|-)" ) {
  16.     $header = str_replace( " ",   " ".$exp, $header );
  17.     $header = str_replace( "-",   "-".$exp, $header );
  18.     $header_arr = explode($exp, $header);
  19.     $lenth=0;
  20.     foreach ( $header_arr as $ka=>$kv ) {
  21.         $lenth =    $lenth+strlen($kv);
  22.         if ($lenth>$in_line) { $header_arr[$ka]="<br>".$kv; $lenth=0; }
  23.     }
  24.     return implode("", $header_arr);
  25. }
  26. }
  27. // RU: как использовать
  28. // EN: how to use
  29. $header = " функция делит строку header на несколько строк с помощью <br>, если длина слова превышает in_line=20. Делит по пробелу и чёрточке. Предполагается, что в тексте нигде не встречается...";
  30. echo br_text_by_strlen ($header);
  31. ?>
Добавить комментарий

Добавить комментарий
Пожалуйста, залогиньтесь для добавления комментария.
Рейтинги
HTML-code and BB-code for blogs and forums

<a href="https://php-fusion.vveb.ws/php-fusion.php?id=6">br_text_by_strlen() PHP-Функция для записи текста в столбик определённой ширины знаков</a>


[url=https://php-fusion.vveb.ws/php-fusion.php?id=6]br_text_by_strlen() PHP-Функция для записи текста в столбик определённой ширины знаков[/url]

Language: Default
 
Код для PHP-Fusion