How to return only part of a feild from database using php substr but to take into account spaces I recently needed to get data from a mysql data base but only wanted to return the first 35 characters, but did not want it to cut off in the middle of a word so wanted to make sure that it checked for a space after that and cut off after that space.
Firstly though I had to check that there were enough characters otherwise it would return a false, also if the cutoff point was the last word it would also cut off as it would not find a space, so would return a blank, so in both cases I used the original text as that was fine.
Otherwise it then used the formula below, change len to be the number of characters you want to return. If you have a set number and cant exceed that number just make your $len about 15 lower than you want that should always return less.
Trending right now
What is the difference between Jam and peanut butter Joke on how i met your mother Some things I am selling please have a look The Hidden Question That Tricks Your Brain Into Attracting Massive Wealth Effortlessly The Hidden Question That Tricks Your Brain Into Attracting Massive Wealth Effortlessly Contrails or chemtrails Single duvet featuring caticorn ie cat like a uncorn white and pink Can you download your ebay listings into an excel spreadsheet How to send a postal cheque to lloyds bank plc Simple easy way to get out of jury service with no hassle. What have we learnt about humanity since covid appeared. Council Tax attachment of earnings removal letter How to return only part of a feild from database using php substr but to take into account spaces
|