wordwrap() function will Wraps a string to a given number of width using a string break character.
[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|left|left|left”]
Name, Required /Optional, Value Type, Description
string, Required, String, It is the input string on which function will be performed.
width, Optional, Integer, It tells about the specific line width. Default width is 75.
break, Optional, User defined characters, It tells about the character with which string is to be splitted. Default break character is “\n”.
cut, Optional, Boolean, Specifies whether words longer than the specified width should be wrapped.If the cut is set to TRUE. String is always wrapped at or before the specified width. So if you have a word that is larger than the given “width” it is broken apart. (See second example). When FALSE the function does not split the word even if the width is smaller than the word width. TRUE – Wrap. FALSE – Default. No-wrap
[/table]
This will return a wrapped string of the specified length.
Related articles : chunk_split() , nl2br().
<?php $strExample = "An example of a wordwrap() function"; echo wordwrap($strExample,15,"\n"); ?>
In above example ,We have a string ‘An example of a wordwrap() function’. Now this function will wrapped a string to 15characters width of line separated by break character i.e. “\n” or you an say new line character. See below is the output of above code.
If you want to break string with 10 characters width in a line and set the parameter cut = TRUE , this will break the long words to 10 characters also. See below example :
<?php $strExample = "Keep working on learning newthings at tutorialmines"; echo wordwrap($strExample,10,"\n",True); ?>
Output will be like below:
wordwrap – PHP Functions Example 3 :
If you want to break string with 10 characters width in a line and set the parameter cut = FALSE , this will not break the long words to 10 characters, while this will keep them intact. See below example :
<?php $strExample = "Keep working on learningnewthingsat tutorialmines"; echo wordwrap($strExample,10,"\n",false); ?>
Output will be like below:
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…