How can PHP functions like sub_str(), wordwrap(), and explode() be utilized effectively to manipulate text data in PHP applications?
To manipulate text data in PHP applications, functions like sub_str(), wordwrap(), and explode() can be utilized effectively. sub_str() can extract a portion of a string, wordwrap() can wrap a string to a certain number of characters per line, and explode() can split a string into an array based on a delimiter. Example PHP code snippet:
// Using substr() to extract a portion of a string
$text = "Hello, World!";
$substring = substr($text, 0, 5); // Output: "Hello"
// Using wordwrap() to wrap a string to a certain number of characters per line
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
$wrappedText = wordwrap($text, 20, "<br>"); // Output: "Lorem ipsum dolor <br>sit amet, <br>consectetur <br>adipiscing elit."
// Using explode() to split a string into an array based on a delimiter
$text = "apple,banana,orange";
$fruits = explode(",", $text); // Output: ["apple", "banana", "orange"]