Ignore html and bbcode?


Posted on 16th Feb 2014 07:03 pm by admin

I've created a function to limit the amount of text according to the amount of words.

However it ruins html and bbcode tags.. . I only want it to have affect on everything else within $text but not bbcode & html.

Did you know?Explore Trending and Topic pages for more stories like this.
Heres the code:
<?php

function containText($text, $length) {

$words= explode(' ', $text); // string to array
foreach ($words as $word) {
$break = 0;
for ($i = 0; $i < strlen($word); $i++) {
if ($break >= $length) {
$word= wordwrap($word, $length, '-
', true); //add
every $length chars
$break = 0;
}
$break++;

}
$newText[] = $word; //add word to array
}
$text = implode(' ', $newText); //array to string

$text = wordwrap($text, $length, "<br />n");
return $text;
}


$text = "PHPfreaks is awesome!!!!!
Lets Party! [img]http://awesome.gif[/img]
<img src="image.gif"> Yay!
<a href="http://www.phpfreaks.com">Woot</a>
[font=2]BIG![/font]";


print containText($text, 10);

?>
No comments posted yet

Your Answer:

Login to answer
277 Like 35 Dislike
Previous forums Next forums
Other forums

PHP Error
On my .php page I have a drop down box that has several names in it. When a user clicks the name &am

Array becomes unset by itself?
Hi,

I have a bit of experience with PHP but not extensive. It seems I cannot store any items

Implementing Single Sign-On using SAML 1.1, x.509, LDAP in C#.net
Hi, I got a requirement from the client i.e implementing single sing on using SAML 1.1( LDAP &

Displaying values from a SQL count...
Hi,
Easy enough question i just forget the exact method ..
I have ...

Code: //count win

how to get values from $_Post with onchange="form.submit();"?
Hi, I have a form that submit to itself with a file upload field and two other hidden field values.<

creating a 1 to 100 in a table
hi guys I am a newb in php need some help.

I have a table with 1 column and 100 rows and in

simplexml and xpath - Need some help
Hello,

I am trying to parse an xml which comes back from Amazon and I am trying to know how m

Convert Binary String to Decimal
Trying to Get:
Decimal: 305419896

Out of:
Binary String: xV4

Call db table from any PHP file
Hi,

I want to be able to call a database table that will be setup in another file called init

Mail from PHP form not always ending up in my inbox?
Hi guys,

I'm a real newbie to PHP and have managed to put together a simple mail form that se

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash