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

array_combine() trouble w/csv file
I have a problem with a piece of code I wrote to import some records from a csv file into mysql. I h

How to login with SAPCPIC userid
I have changed the Password for SAPCPIC in Development Server for 000,001 and 100 client.
But w

Using mysql_real_escape_string for displayed content
On my website users can input data into a textarea and it will store it in the mysql database. But,

Problem with creating FI documents
Hi, Experts!

when i create Fi doc. with standart transaction, i ve been had such problem

Navigation include for all site directories
Hi,

I need a navigation include that can deal with directories at different levels on a site.

Sending a hyperlink through mail
HI all,
I am sending a mail to outlook mailbox of a user using FM SO_NEW_DOCUMENT_ATT_S

why is it over writing
Code: $filepaths[] = $_FILES['new_image'];
foreach ($filepaths as $filepath)
{
$imagename =

PHP Include not working
The website is http://www.grlistingservices.com

The code block is as follows:

<

Converting numbers to months
The porgram works -just need the last function(month_convert_ to convert numbers to months -thanks.

Looking for help reading a .txt or .ini file and outputting the info.
I have a file called Info.ini and It has the following info:
Code: [General]
Online=0
I wou

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