is there a way to break up only long words? because I have a certain table with posts on it but when using “$myString = wordwrap($blabs, 42, “<br />”, true);” everthing is wordwrapped and the normal text is too short (doesn’t extend all the way).
On the other hand, if I increase the number to 75 for example “$myString = wordwrap($blabs, 75, “<br />”, true);” normal text fits fine but capital WWWWWWWW will extend the line and the table since 75 (Ws) takes up more space than normal 75 characters.
So can I just break up long words without breaking up normal text with spaces?
I searched but it didn’t seem possible.
essentially yes you can do what you are trying to achieve. Not sure about hyphenating long words specifically but I have come across this issue before. Both while programming something for users to add content to a site, and while just doing html/css as a freelancer.
I’m afraid I can’t be too specific right now but I have an image of what you want and what the problem is. You are going about it the wrong way. Yes you need to say how big the “box” is, and if you want to count that in chars or ems then fine, whatever. But it’s probably best to leave the computer to decide what to do with those extra-long words. I think that’s what’s keeping you going around in circles.
Look for functions in php AND/OR css that will allow you to control the breaking/wrapping of text. If you try to hard-code some rule for how long the words should be and where they break you are going to come unstuck. If you say all words over x letters need to break after y letters you could end up with some really strange-looking stuff.
Honestly, I didn’t think this was possible for ages but finally I found out how it could be done. It’s 2am here. I’m not going to look it up for you now. But I do a lot of work for a publisher and this is the kind of thing they get obsessed over!
Hope that helps. Sorry not to be more use.
EDIT: I see you already found a php function. Maybe check out css solutions INSTEAD and just make your php solution (or the size of the table cell itself) an outer limit. Use CSS!!! (or mayhap you have no say in that? In which case, good luck …).
//slap me if I am wrong …
JUST REMEMBERED SOMETHING:
I think perhaps one thing I did that helped was actually controlling the size of the box people typed their posts into. Then you can preformat the text and spit it out into something that matches in “size”. It did take a little bit of lateral thinking to get it right but it WORKS. That’s NOT the only solution to the general problem - often I don’t have any say at all in what the text is or where it goes. I just get told to “do it like such, make it happen!”. Rarely it’s actually impossible, and unless this is some specialist website with ridiculous long words it should be possible to achieve a pleasing effect. I’m more likely to get frustrated by editors who demand that the problem be solved by a hard-coded line break, when they can’t understand that the boxes are all stretchy and that just means someone with a bigger screen or different browser gets a really crappy looking thing … oh well. Give me the luxury of spending a day or two figuring out a nice solution over that any time!
Ya I’ll try to play around with CSS, although I’m new to it. Hopefully that works out. And I’ll check other screens (wider or narrower) to see what happens with the code that I have left in there for the moment.
I appreciate the time you put in trying to help me.
If I can think of anything more specific I’ll let you know, but unfortunately I have a very busy work day today.
Good luck with it - it seems you hadn’t explored all the options after all!
Remember there’s more than one way to skin a cat!