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:
App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…
As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…
Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…
COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…
Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…
For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…