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
How to count how many records of a field are in a database Encouraging Messages from God How to make first letter only captial using php. How I paid my HMRC tax bill with a promissory note Send the Single Letter template to anyone demanding money from you Customers or leads you decide Why Ditching the News Could Transform Your Mental Health Learn Spanish as it is spoken quickly and easily. I will bid on your ebay items to increase the price Miracles Will Happen For 24 hours after reading Paper chain How to Transform Your Product into a Coveted Luxury Item Promissory Notes and Bills of Exchange Why Blind Faith Leads to Catastrophe Why Your Prescription Drugs Might Be Hiding the Real Problem How to Boost Your Prices Without Driving Customers Away A miracle is on its way to you right now How to stop a form submitting when you press enter php Why Discipline Beats Motivation Every Time How to stop vomiting How to unmark posting as spam on facebook Getting Lots of Visitors to Your Website or Social Media with Few Followers Hacking Your Way to Success How to return only part of a feild from database using php substr but to take into account spaces All tax is illegal Why You Should Launch Your Business Now and Ditch the Quest for Perfection Why Letting Go is the Key to Scaling Your Business Service Arbitrage Keep flies off your food this summer How to force a file to download simple Download free instructions for the game chad valley link letters How to reject an invoice for council tax or any other invoice Hide
|