TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   hey i ned help on BBcode (http://www.talkphp.com/absolute-beginners/2419-hey-i-ned-help-bbcode.html)

webtuto 03-04-2008 06:08 PM

hey i ned help on BBcode
 
hey , i wanna use bbcode on my script (textarea)
i wanna allow visitors to make text bold and add photos , things like that
so how can i do that ??
i really need help on that
thanks !!

Alan @ CIT 03-04-2008 06:19 PM

The basic process is fairly straightforward - your script just searches for the BBCode tag and replaces it with the HTML equivelent.

For example, for bold it would search for [b] and replace it with <strong>.

It can get complex when you start dealing with complex BBCode (for example, Invision Board's BBCode parser comes in at just under 4,000 lines of code) but don't worry about that for now :-)

Also, there is a BBCode extension which may help - PHP: BBCode - Manual

Alan

webtuto 03-04-2008 06:23 PM

thanks im using this code but it didnt succeed =>
$t=str_replace("[b]", "<b>", $text);
$text = htmlentities($tuto['message']);
if($v = eregi('<' , $string)){
echo "no html cods";
}

and the output i show it on another page , but it give blank page

abiko 03-04-2008 06:26 PM

Here is a nice BBcode class - with documentation :)

webtuto 03-04-2008 07:07 PM

ah i tried this class but i think i didnt know how to use even of the documentation
could you explain to me how to use this class

i did that =>
require_once 'stringparser_bbcode.class.php';


and i copy everything to my folder
but nothing :s

Gareth 03-04-2008 08:00 PM

I sent you a PM with an answer.

Gareth 03-04-2008 08:43 PM

Ahh, do you mean a WYSIWYG editor?

Salathe 03-05-2008 09:17 PM

Gareth, unless there's any particular reason why the answer needs to be private, I'm sure it would benefit the whole community if all answers were posted publicly. It provides a flow of conversation and an archive of information for people coming back to look at this topic in the future.

webtuto 03-07-2008 12:14 PM

Quote:

Originally Posted by Gareth (Post 11998)
Ahh, do you mean a WYSIWYG editor?

YEAH I MEAN WYSIWYG editor

Alan @ CIT 03-07-2008 05:52 PM

If you want a WYSIWYG editor I would recomend using - TinyMCE Javascript Content Editor by Moxiecode Systems AB - it's fully functional with plenty of documentation and example code :-)

Alan

marxx 03-20-2008 10:54 AM

Well, if you end up using simple function (or someone else need help whit it) here is one simple parser.

PHP Code:

function bbcode_format($var) {
    
$search = array(
        
'/\[b\](.*?)\[\/b\]/is',                                
        
'/\[i\](.*?)\[\/i\]/is',                                
        
'/\[u\](.*?)\[\/u\]/is',
        
'/\[img\](.*?)\[\/img\]/is',
        
'/\[url\](.*?)\[\/url\]/is',
        
'/\[url\=(.*?)\](.*?)\[\/url\]/is'
        
);

    
$replace = array(
        
'<strong>$1</strong>',
        
'<em>$1</em>',
        
'<u>$1</u>',
        
'<img src="$1" />',
        
'<a href="$1">$1</a>',
        
'<a href="$1">$2</a>'
        
);

    
$var preg_replace ($search$replace$var);

    return 
$var;


usage:
PHP Code:


$text 
"This is [b]example[/b] text whit
 [url=http://www.google.com]google link[/url]"
;

echo 
bbcode_format($text); 

will look like:

This is example text whit google link.

=)

ETbyrne 03-20-2008 04:45 PM

Wow, great job marxx! I've got to try this.


All times are GMT. The time now is 08:15 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0