Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> wordwrap, ale bez tagow
-Guest-
post
Post #1





Goście







widzialem juz opisy tego problemu na forum, ale bez odpowiedzi
jak podzielic za dlugi tekst ale bez ruszania tagow

czyli jesli wordwrap dzieli po np. 10 znakach a mamy ciag:

123456789<img src=...>abc to ciachanie nastepuje po literce a a nie po nawiasie ostrym

jak to zrobic?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
hwao
post
Post #2


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




zródło : http://pl.php.net/wordwrap

  1. <?php
  2. function even_better_wordwrap($str,$cols,$cut) {
  3.  $tag_open = '<';
  4.  $tag_close = '>';
  5.  $count = 0;
  6.  $in_tag = 0;
  7.  $str_len = strlen($str);
  8.  $segment_width = 0;
  9.  
  10.  for ($i=; $i<=$str_len ; $i++){
  11.  if ($str[$i] == $tag_open) {
  12.  $in_tag++;
  13.  } elseif ($str[$i] == $tag_close) {
  14.  if ($in_tag > 0) {
  15.  $in_tag--;
  16.  }
  17.  } else {
  18.  if ($in_tag == 0) {
  19.  $segment_width++;
  20.  if (($segment_width > $cols) && ($str[$i] != &#092;" \")) {
  21.  $str = substr($str,0,$i).$cut.substr($str,$i+1,$str_len-1);
  22.  $i += strlen($cut);
  23.  $str_len = strlen($str);
  24.  $segment_width = 0;
  25.  }
  26.  }
  27.  }
  28.  }
  29.  return $str;
  30. }
  31. ?>


ALbo: http://www.greywyvern.com/code/php/htmlwrap_1.1.php.txt
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 13:50