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

Foods to avoid during H pylori infection

Hide

Even Crap sells

How to stop videos playing automatically in chrome

How to identify hot selling products on Ebay

How to get more customers

Why Eating Butter Before Bed Could Transform Your Night

Keep flies off your food this summer

Master the Art of Saying No Without Guilt

How to tie a tie

How do i edit a facebook album name in a group

How to make first letter only captial using php.

The Quickest Ever Salt Dough Recipe

Encouraging Messages from God

To get a free starter from pizza express simply enter this code

How to stop text enhance pop ups showing on webpages.

What Is Money and How It Is Just a Collective Illusion

Today is your day

Made to measure drawer organisers. Easy to install.

How to stop people stealing your downloads when using paypal

People Do not Really Care And That is the Truth

Giving your bank details to Trustly through ebay

What different Text Ads Types are available for Google ADWORDS

How to stop someone uploading photos of you or your child

Delete Remove a file from your sever using php

How to stop coughing quickly and easily

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

Why are the vaccinated not actually vaccinated

Remove a tomato stain from clothes easily

How to copy a textarea contents to a clipboard

Visited link to remain same colour

How to make sure facebook picks up the correct picture from a website

How to remove inspyware from your laptop

How to relieve cure a sore throat

Why No One Should Ever Verify Their Details on Any Website

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

Share







SubmitExpress.com