/    Sign up×
Community /Pin to ProfileBookmark

Restricting content from Mysql

Hello all

I wonder if anyone can offer me a snippet of advice or point me in the direction of a good article that would cover this.

My query is concerning my [URL=”http://www.yournorwich.com/eventlist.php”]Event Listing Pages[/URL]

As you can see at present all the information is displayed for the site users to view and search.
The problem i have with this is that occasionally a user will submit masses of information into the description field which is creating huge pages.
Now as i don’t wish to put restrictions on the information they can enter into the description i need to find out how to limit what is being displayed.

So instead of what is being displayed in the description field now i would like to limit this to 250 characters and add a “…..more info.” link in at the end so they can click this if they wish to see the full advert with the full description in a new page.

Now whilst i can create the links to the new page with the full description on i feel i need advice on the php and query that will generate only these first 250 characters (without spaces) and display the “…more info.” link only if the description in Mysql is actually over this 250 character mark.

I recently found a tutorial that covered this quiet well but made a massive mistake when i didnt bookmark it…

so if anyone has any advice or maybe suggestions on other methods around this it would be most appreciated..

Thanks for looking
Bolty2uk

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 28.2007 — Assume $text contains the text to be displayed:
[code=php]
if(strlen($text) > 250)
{
$text = preg_replace('/^.{1,250}b/s', '\0...', $text);
}
[/code]

This will break the string at the word break closest to (but not more than) the 250th character of the string.
×

Success!

Help @bolty2uk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...