Jump to content

[SOLVED] Split String in Middle and Preserve String!


musclehead

Recommended Posts

I have a script that churns out a string of variables and is displayed on the page. If this string length is within a certain amount of characters, it is displayed, plain and simple.

 

However, if the string length is > 100 characters, I want to be able to insert a line break (without breaking a word in the string) to avoid clipping data. Example:

 

$myString = "This is a string, that, for the sake of argument, will be more than the 100-character threshold";

if (str_len($myString) > 100){
  ...

 

That's where I'm stuck - I want to be able to split the string in half without risking a word being cut in-half or breaking grammar.

 

Any ideas?

Archived

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

×
×
  • Create New...

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.