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.

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

Record count of entire database
Does anyone know if there is a way to obtain the number of records in each table of the database usi

mod_rewrite.c on windows ??
why it's not working on windows while it's working on other hosts???

this is the code i got

login from external site
Hi my new experience begins, Now what i am trying to do is i make three pages, login.php logout.php

Saving data from a form into a file
Hey everybody,

Sorry, I am really new to PHP coding and such but a project kind of got thrust

php - xml what is the best way to do this.
IN essence I want to have a script calling the info from the database.. I have no problem thus far,

URL Rewrite issue
Im created a series of Rewrites and on page checks to make sure the correct url is being called. But

While Problem
i am having a problem with a while statement here is the code
Code: [Select]<?php
sess

filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h

Material xxx does not exist in plant xxx
Dear All,

I am working for a steel project which is repetitive manufacturing.

session_destroy();
new to php
I have a simple login and am trying to write a logout.
I set a $_SESSION var to 1 i

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