You are reading the article How Wordwrap() Function Works In Php updated in September 2023 on the website Khongconthamnam.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How Wordwrap() Function Works In Php
Introduction to PHP wordwrap()The PHP wordwrap() function of the PHP Programming Language is actually an inbuilt function which helps to wrap a string into many number of characters with the help of a break character inside of the wordwrap() function. It runs only for the PHP 4.0.2 version and also for other above PHP versions in order to support the function. This PHP wordwrap() function helps in wrapping a string into many new lines when it is going to reach to its given length. This function is one the best function when handling the string function in the PHP Programming Language and in some other languages too.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax wordwrap($str1, $width1, $break1, $cut1)The wordwrap() function of the PHP Programming Language usually accepts four parameters as mentioned above under the syntax section.
$str1: The $str1 Parameter of the wordwrap() function is actually helps in specifying the input string which is actually need to breakup into many lines.
$width1: The $width1 Parameter of the wordwrap() function is actually helps in specifying the number of characters at which point the string has to be/will be wrapped. These are the number of the characters after which the string value will break.
$break1: The $break1 Parameter of the wordwrap() function is actually an optional parameter but if it is specified then it will append the value at the exact point of string break.
$cut1: The $cut1 Parameter of the wordwrap() function is actually a Boolean parameter. If this $cut1 parameter value is set to TRUE value then the string is always going to be wrapped at that point or before the exact specified width. That means it is also going to break a word which are between if it comes in the middle of a constraint that is actually specifying the width1 parameter. And if this cut1 parameter is set to the FALSE value then the wordwrap() function don’t even split the word even if the width parameter has less value than the word’s width.
Return Value:
The wordwrap() function helps in returning a string which is wrapped upto the specified length. It is nothing but a string which is going to be broken into many lines on success or FALSE value on failure.
How wordwrap() Function works in PHP?The wordwrap() function of the PHP Programming Language mainly based on the four parameters which are mentioned inside of the wordwrap() function. It works by wrapping the given string into number of characters by using the breaking character “break character” but this only works for PHP 4.0.2 and for other above PHP versions. Below are the examples to implement:
Example #1Code:
<?php $text1 = "My Name is Pavan Kumar Sake."; echo "$newtext1";Output:
Example #2Code:
<?php $stringn1 = "Pavan Kumar Sake a Blogger PhysicsNerd and BusinessMan"; $width1 = 10; echo wordwrap($stringn1, $width1, $break1); Example #3Code:
<?php $stringn1 = "Congratulations! Pavan Sake kumar"; $width1 = 8; echo wordwrap($stringn1, $width1, $break1);Output:
Example #4 <?php $stringnn1 = "Congratulations! Power Ranger of the World"; $width11 = 8; $cut11 = true; echo wordwrap($stringnn1, $width11, $break11, $cut11);Output:
Example #5This program is so similar to the example 4 but here $cut1 parameter value is passed with the FALSE value and stringnn1 variable is passed new string value, width parameter is mentioned with 7 as value. So the output will be different. For bigger strings or smaller strings, whole strings will be printed after some spaces like that. But most of the time the width of the strings which are wrapped will be of the length “7”.
Code:
<?php $stringnn1 = "Be a part of Game Changer :: profitloops"; $width11 = 7; $cut11 = false; echo wordwrap($stringnn1, $width11, $break11, $cut11);Output:
ConclusionI hope you learnt what is the definition of PHP wordwrap() function along with its syntax with all the parameters explanation, How the wordwrap() function works in PHP Programming language along with various examples of implementing the wordwrap() function to understand the wordwrap() function better.
Recommended ArticlesThis is a guide to PHP wordwrap(). Here we discuss an introduction, syntax, and working of wordwrap() in PHP along with different examples and code implementation. You can also go through our other related articles to learn more –
You're reading How Wordwrap() Function Works In Php
Update the detailed information about How Wordwrap() Function Works In Php on the Khongconthamnam.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!