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

Sequencing or queuing parallel process
Scenario is as follows
There is one parent process say P1 and 4 child processes say A B C D

start new row of pictures
on my site www.budstreasureauctions.com there is a featured auctions box that users will pay to get

how do i display data on a page from mysql
1 - do i use this code at the top of each of my page i wish to only alow access if there as been a s

Mail sending is slow on server
Why mail is taking time to be send on apache-linux server

Including calander to page - will not show other months than current??
im trying to add an existaing calander onto a profile page by using Code: <?php include "

Creating web pages by php
Hello again,
I was just wondering us there a way to use a php script to create a new web page. I

issues verifying if user is logged in
I am having issues when a user logs in via asp Login control, the IsAuthenticated still seems to com

Beginner question regarding Array's
Hi everyone, the page im working on has an array of variable at the top...

Code: $define_li

simple ping code
been searchin the site/web and found code thats simple but doesnt work.

I have a personal we

SOAP Issue
Hi,

I am facing some understanding problem with SOAP basic.kindly recommend some SOAP expert.

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