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

We will write to any debt collectors and get them to stop harassing you no matter who they represent

Does Salt and Water Cure Hayfever

Promissory Notes and Bills of Exchange

Natural Remedies and Dietary Approach for Psoriasis

Giving your bank details to Trustly through ebay

How to cure an ear infection without antibiotics

Good businesses to start with no experience

How to stop any interaction with any police officer immediately

Boost your business Promote your site here for free

How to limit the number of records mysql produces

Excellent Snacks to have on the carnivore diet

Enable the hidden admin on windows 10

How to remove background from a photo image online

How to stop paying your tv licence

Help my boyfriend wants me to send a naked picture

How to stop vomiting

How to delete a tag from someone elses photo of me

The only cough remedy that really works

Elegant Input box css

The One Simple Trick to Skyrocket Your Small Business Growth

Healing pneumonia with raw ginger

How to Boost Your Prices Without Driving Customers Away

Lowell debt collection agency. How to get them off your back.

Abundance rules

A Beginners Guide to Fitness for Women Over 50

What to say when someone asks where is your mask

What is the difference between Jam and peanut butter Joke on how i met your mother

How to ensure your invoices get paid

Why You Should Launch Your Business Now and Ditch the Quest for Perfection

How to stop someone uploading photos of you or your child

How to get your child into rainbows brownies guiding scouts beavers when there is a waiting list

Quickest and best energy boost ever

Electric companies applying for a warrant and how to stop them.

Share