count a string, if its >= 10 then do something

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

count a string, if its >= 10 then do something

Post by Jim_Bo »

Hi,

How can u count a string, then if its over 10 characters do something?

Code: Select all

if (count($row['description'] >= 10)) {
	$readmore = 'Do this';
}

Thanks
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post by kaszu »

Code: Select all

$string_length = strlen($string);
From php manual:
count — Count elements in an array, or properties in an object
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Thanks for that ..

Is there a way to strip bbcode out of the string b4 its counted?


Cheers
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

preg_replace()

I'd imagine something like....

Code: Select all

$text = preg_replace("/\[\w+\]/", '', $text);
Although, you should ideally replace only the bbtags you have, instead of anything inside of [ ].
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply