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.

 


👟
Tiny Steps Weight Loss Coach
1:1 Daily WhatsApp Coaching • £30/month
Start Your Transformation Today £30 / month
✅ Personalised Plans
✅ Daily Check-ins
✅ No Burnout Method
✅ Cancel Anytime

Trending right now

We will transform any word or google docs document into a pdf sized applicable to create a amazonkdp

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

The Hidden Question That Tricks Your Brain Into Attracting Massive Wealth Effortlessly

The Hidden Question That Tricks Your Brain Into Attracting Massive Wealth Effortlessly

Modifying MS Word Normal.dot .dotm template

Am I an antivaxer

Promissory Notes and Bills of Exchange

Paper chain

How to create a date array in php which come up with todays date selected

Hacking Your Way to Success

Why Solving One Problem Well Is the Key to Business Success

How to redirect to another web page immediately using meta refresh

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

How to limit the number of records mysql produces

How to remove inspyware from your laptop

If the covid vaccine is safe and effective why does someone need to be around you for 15 minutes aft

How to tie a tie

Ebay Scam buyer has said that parcel has not arrived

Climate change is it real or made up.

How to identify hot selling products on Ebay

Even Crap sells

Deregister letter for school for England. How to deregister your child from school

Why Eating Butter Before Bed Could Transform Your Night

Made to measure drawer organisers. Easy to install.

Start a Profitable Mobile Car Valeting Business in the UK Today

How I stopped my craving for chocolate

How to stop someone uploading photos of you or your child

How to remove a ccj from your credit file

Natural Remedies and Dietary Approach for Psoriasis

Today is your day

Drop down list of towns and cities in England

How I paid my HMRC tax bill with a promissory note

How to return only part of a feild from database using php substr but to take into account spaces

Share







SubmitExpress.com