Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 13th, 2006, 11:00 AM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default preg_match

Hi,

I'm working on returning some results from a DB and only want to return the first 100 characters. I've gotten to this point, but it seems to have problems...

<?
$text = $row1[NewsDescription];
preg_match('#^\s*(.{100,}?)\s+.*$#', $text, $match2);
echo $match2[0].' ...';
?>

that should return somthing like...

blah blah blah blah blah ...

but it doesnt work properly, is there a different way to achieve the same result?

Cheers
Ash:)

My new web design domain
www.askmultimedia.co.uk
__________________
My new web design domain
www.askmultimedia.co.uk
 
Old November 13th, 2006, 01:39 PM
Authorized User
 
Join Date: Oct 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

To just print out the first (whatever) number of characters of a returned variable use:

substr($variable, 100)

This will print out the first 100 characters

HTH
David









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.