wordwrap funksiyasi

wordwrap funksiyasi har N belgidan keyin satr uzatish belgisini (standart \n) kiritadi (standart 75).

Sintaksis

phpwordwrap(string $string, int $width = 75, string $break = "\n", bool $cut_long_words = false): string

Misol

Ushbu misolda funksiya satrni 10 belgidan uzatish bilan bo'ladi:

php<?php
  $text = "Quick brown fox jumps over lazy dog";
  echo wordwrap($text, 10, "<br>\n");
?>

Kodni bajarish natijasi:

phpQuick<br>
brown fox<br>
jumps over<br>
lazy dog

Misol

Uzoq so'zlarni majburiy uzish bilan misol:

php<?php
  $text = "Supercalifragilisticexpialidocious wordwrap example";
  echo wordwrap($text, 8, "<br>\n", true);
?>

Kodni bajarish natijasi:

phpSupercal<br>
ifragil<br>
isticexp<br>
ialidoc<br>
ious<br>
wordwra<br>
p<br>
example

Misol

Uzoq URL satri bilan misol:

php<?php
  $url = "https://www.example.com/very/long/url/path/to/some/resource";
  echo wordwrap($url, 20, "<br>\n", true);
?>

Kodni bajarish natijasi:

phphttps://www.exampl<br>
e.com/very/long/u<br>
rl/path/to/some/<br>
resource

Shuningdek qarang

  • nl2br funksiyasi,
    bu satr uzatish belgisidan keyin br tegni kiritadi