What is the purpose of the wordwrap() function in PHP and how is it used in the context of text formatting?
The wordwrap() function in PHP is used to wrap a string to a given number of characters. This is useful for formatting text to fit within a certain width, especially when displaying text in a fixed-width container like a terminal or a webpage. By specifying the desired line length, the wordwrap() function breaks the string into multiple lines without breaking words.
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
$wrapped_text = wordwrap($text, 30, "<br>");
echo $wrapped_text;
Keywords
Related Questions
- What best practices should be followed when creating a countdown timer in PHP that counts down from a specific time without date information?
- What are the potential risks of storing passwords in a hashed format using a one-way encryption method in PHP?
- How can Object-Oriented Programming (OOP) be applied effectively in PHP when creating a forum?