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 make first letter only captial using php.

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

Encouraging Messages from God

How I paid my HMRC tax bill with a promissory note

I will bid on your ebay items to increase the price

How to unmark posting as spam on facebook

How to count how many records of a field are in a database

Stop paying council tax and remove yourself from their database

How to stop paying your Council Tax

Enable the hidden admin on windows 10

How to stop a form submitting when you press enter php

How to stop vomiting

How to stop bank scammers over the phone quickly and easily

Paper chain

How to force a file to download simple

How to stop google chrome downloading automatically

How to stop paying your tv licence

A miracle is on its way to you right now

Drop down list of towns and cities in England

Why Higher Prices Attract Better Customers and Boost Your Business

The One Question That Could Change Your Life Forever

Good businesses to start with no experience

How to relieve cure a sore throat

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

Dhlpay.co.uk spam text email mob 07494431073

Healing pneumonia with raw ginger

Amount not showing in my account but has left the buyers account

Parking charge Notice by private car parks not council.

Foods to avoid during H pylori infection

Ebay Scam buyer has said that parcel has not arrived

People Do not Really Care And That is the Truth

Council Tax attachment of earnings removal letter

How to reject an invoice for council tax or any other invoice

Why Ditching the News Could Transform Your Mental Health

How to unblock a plug hole in your bath

Share