hi, i am trying to make my own 'truncate' function for strings, in which if the string is longer than desired length, i should truncate and add '...', but if the truncation occurs in the middle of a word, there should not be any word pieces, just whole words, so the incomplete word should be removed. there are functions in php to search for chars or a string from end to start and from start to end, and i can use those search functions if i give them a string with all spaces, so it can search the last space (searching from the end to the beginning of the string). is there a given 'system constant' that contains all spaces?

tnx

use sub string function to do truncation and then check the next character following last truncated word if it is not space then tokenize the truncated word using space delimiter and remove last token. Then combine the words using space.
There might be better way but that is what I can think of quickly!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.