wordwrap() Function in PHP 8.1 and 8.2 with Example

Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 With Latest All Version Support.

Hello Friends Today, through this tutorial, I will tell you How to Use `wordwrap()` function using PHP, PHP 8, PHP 8.1, PHP 8.2 With Example. In PHP, the `wordwrap()` function is used to wrap a string to a specific line length, breaking it at word boundaries. This function is particularly useful when you want to format text to fit within a certain width, commonly seen in applications dealing with text display or formatting.

Here’s how the `wordwrap()` function works in PHP 8.1 and 8.2 along with an example:

Syntax:

<?php
wordwrap(string $string, int $width, string $break = "\n", bool $cut = false): string|false
?>

1. `$string`: The input string to be wrapped.
2. `$width`: The maximum length of line after wrapping.
3. `$break`: Optional. The character used to break the line. Default is newline character `”\n”`.
4. `$cut`: Optional. If set to `true`, words longer than `$width` will be broken. Default is `false`.

Example:

<?php
$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
// Wrap the string to a maximum width of 30 characters
$wrappedString = wordwrap($string, 30);
echo $wrappedString;
?>

Output:

Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Sed
do eiusmod tempor incididunt ut
labore et dolore magna aliqua.

In this example, the input string is wrapped to a maximum width of 30 characters, breaking it at word boundaries. The resulting string is then echoed, displaying the wrapped text.

You can also use additional parameters like `$break` and `$cut` to customize the behavior of the `wordwrap()` function according to your requirements.

Cialis (Tadalafil) är den främsta konkurrenten till Viagra (Sildenafil) på marknaden för erektil dysfunktion. köpa Cialis i Sverige föredras av många på grund av sin längre varaktighet och anses vara det mest kostnadseffektiva varumärkesbaserade ED-läkemedlet som finns tillgängligt i Sverige. Cialis finns i två varianter: Cialis och Cialis Daily, och fyra olika doseringar: 2,5 mg, 5 mg, 10 mg och 20 mg, erbjuder Cialis också en rad olika alternativ för att passa patientens behov.