Funksioni wordwrap
Funksioni wordwrap fut një karakter thyerjeje rreshti
(parazgjedhur \n) pas çdo N karakteresh
(parazgjedhur 75).
Sintaksa
wordwrap(string $string, int $width = 75, string $break = "\n", bool $cut_long_words = false): string
Shembull
Në këtë shembull, funksioni do ta ndajë stringun në 10 karaktere me thyerje:
<?php
$text = "Quick brown fox jumps over lazy dog";
echo wordwrap($text, 10, "<br>\n");
?>
Rezultati i ekzekutimit të kodit:
Quick<br>
brown fox<br>
jumps over<br>
lazy dog
Shembull
Shembull me thyerje të detyruar të fjalëve të gjata:
<?php
$text = "Supercalifragilisticexpialidocious wordwrap example";
echo wordwrap($text, 8, "<br>\n", true);
?>
Rezultati i ekzekutimit të kodit:
Supercal<br>
ifragil<br>
isticexp<br>
ialidoc<br>
ious<br>
wordwra<br>
p<br>
example
Shembull
Shembull me një URL të gjatë:
<?php
$url = "https://www.example.com/very/long/url/path/to/some/resource";
echo wordwrap($url, 20, "<br>\n", true);
?>
Rezultati i ekzekutimit të kodit:
https://www.exampl<br>
e.com/very/long/u<br>
rl/path/to/some/<br>
resource
Shihni gjithashtu
-
funksionin
nl2br,
i cili fut tag-unbrpas karakterit të thyerjes së rreshtit