Parobola Posted July 19, 2011 Share Posted July 19, 2011 Hello again, I have a problem I need to overcome and cannot fathom how. I need to take a random length character string i.e. "This is a sample of what I need to accomplish." Then I need to separate the character string into lengths that won't push past the boundaries of a FPDF cell. This is easy to do using strlen( ); but if I seperate by string length then I will end up with part of a word one line and part of another word on another line. So what I thought I would do is separate the words using explode(" " , $string); and dump it into an array. Then pull out each word, add it to a string, and use strlen( ); to check my length and use IF (strlen($string) >= 10) {start a new line} ELSE {add another word from array and restart test}. My issue is that I can't figure out how to use the explode function with the array function properly. Any advice on where I can look, or anyone want to give me an example of how I could accomplish this? Link to comment https://forums.phpfreaks.com/topic/242345-help-with-separating-a-text-string/ Share on other sites More sharing options...
WebStyles Posted July 19, 2011 Share Posted July 19, 2011 wordwrap Link to comment https://forums.phpfreaks.com/topic/242345-help-with-separating-a-text-string/#findComment-1244692 Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 $string = "this is a sample string for learning"; $exp = explode(" ",$string); foreach($exp as $value){ if(strlen($value) >= 10){ //do something }else{ // do something else } } since I do not fully understand what exactly you are wanting to do to the strings if they are under 10 chars and above 10 chars, I can't quite finish this code...if you need further help let me know. Edit: wordwrap could be what you want here yes.. Link to comment https://forums.phpfreaks.com/topic/242345-help-with-separating-a-text-string/#findComment-1244693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.