Jump to content

Archived

This topic is now archived and is closed to further replies.

lead2gold

WordWraping function

Recommended Posts

INPUT:
Try to hold in and not show that you feel some coworkers are lazy scum and they should be disiplined severly or removed from service. I would like Eric to treat everyone as if they would decide his future, and in a way many others do decide our future.

Eric from my point of view, you with little effort can work with everyone, and if you hold in your distain for poor work ethic's , we as a group can proceed together to become a team.

Eric you have invested years of hard work, extra hours and helping others by switching holidays, days off and Saturdays and you are a very welcome member of our service department, but there is a cost of membership, which is what I am working on for myself as well; Treat others with respect at all times, even when we feel they may not deserve it.

Learn new tools and ways of doing our job.(spg,ltw,you have aced ECP) Write your Toyota factory Service advisor exam, as always you can win a trip to compete in Canada and then Japan. Compete in overdrive contest. Do service advisor training with Toyota and tire makers , at Toyota u.

OUTPUT:
Try to hold in and not show that you feel some coworkers are lazy scum and they should be disiplined severly or removed from service. I would like Eric to treat everyone as if they would decide his future, and in a way many others do decide our future. Eric from my point of view, you with little effort can work with everyone, and if you hold in your distain for poor work ethic's , we as a group can proceed together to become a team. Eric you have invested years of hard work, extra hours and helping others by switching holidays, days off and Saturdays and you are a very welcome member of our service department, but there is a cost of membership, which is what I am working on for myself as well; Treat others with respect at all times, even when we feel they may not deserve

FUNCTION:
[code]
function cc_truncate($string, $width, $max_cr)
{
    $formatted_text = wordwrap($string,$width,"\n");
    $complete_array = explode("\n",$formatted_text); //turns the string into an array
    $clean_array = array_slice($complete_array, 0, $max_cr); //takes the first max_cr elements (lines) of the array
    $clean_text = implode(" ",$clean_array); //puts the string back together, with \n after each element in the array
    return $clean_text;
}
[/code]

CALL:
[code]
cc_truncate($a->new_objectives, 80,11)
[/code]

Thus: max characters of 80 wide, and 11 deep

DESIRED OUTPUT:
Try to hold in and not show that you feel some coworkers are lazy scum and they should be disiplined severly or removed from service. I would like Eric to treat everyone as if they would decide his future, and in
a way many others do decide our future.

Eric from my point of view, you with little effort can work with everyone, and if you hold in your distain for poor work ethic's , we as a group can proceed together to become a team.

Eric you have invested years of hard work, extra hours and helping others by switching holidays, days off and Saturdays and you are a very welcome member of our service department, but there is a cost of membership, which is what I am working on for myself as well; Treat others with respect at all times, even when we feel they may not deserve it.

<-- chopped off -->

Learn new tools and ways of doing our job.(spg,ltw,you have aced ECP) Write your Toyota factory Service advisor exam, as always you can win a trip to compete in Canada and then Japan. Compete in overdrive contest. Do service advisor training with Toyota and tire makers , at Toyota u.

----------------------------------------
Thus after 80 characters, a new line is forced.

What seems to be happening is that the existing carrage returns are also getting tangled up with the new carrage returns wordwrap() inserts. it seems wordwrap() ignores existing carrage returns and treats them like a regular character (thus wraps \n's at bizzare locations)


How can i adjust the wordwrap function to achieve my goals?

Share this post


Link to post
Share on other sites
you can add str_replace in first to remove all the carraige returns then use your existing wordwrap code.

[code]$newstring = str_replace("\n", "", $string);[/code]

Ray

Share this post


Link to post
Share on other sites
[!--quoteo(post=353626:date=Mar 10 2006, 09:46 AM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 10 2006, 09:46 AM) [snapback]353626[/snapback][/div][div class=\'quotemain\'][!--quotec--]
you can add str_replace in first to remove all the carraige returns then use your existing wordwrap code.

[code]$newstring = str_replace("\n", "", $string);[/code]

Ray
[/quote]

Thanks, but then all the formatting is lost.... :(
I will use this for a temporary workaround i guess until i find a sollution

Edit: Sorry for the double post, i thought my browser froze so i pressed back, and saved it again

Share this post


Link to post
Share on other sites
[!--quoteo(post=353626:date=Mar 10 2006, 09:46 AM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 10 2006, 09:46 AM) [snapback]353626[/snapback][/div][div class=\'quotemain\'][!--quotec--]
you can add str_replace in first to remove all the carraige returns then use your existing wordwrap code.

[code]$newstring = str_replace("\n", "", $string);[/code]

Ray
[/quote]

Thanks, but then all the formatting is lost.... :(
I will use this for a temporary workaround i guess until i find a sollution

Share this post


Link to post
Share on other sites
try

[code]$paras = explode ("\n", $input);

foreach ($paras as $p) {
         echo nl2br(wordwrap($p, 80));
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.