Page 1 of 1

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

Posted: Wed Feb 07, 2007 2:14 am
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

Posted: Wed Feb 07, 2007 2:21 am
by kaszu

Code: Select all

$string_length = strlen($string);
From php manual:
count — Count elements in an array, or properties in an object

Posted: Wed Feb 07, 2007 3:28 am
by Jim_Bo
Thanks for that ..

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


Cheers

Posted: Wed Feb 07, 2007 7:40 am
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 [ ].