Jump to content

Text Formatting?


TeddyKiller

Recommended Posts

I'm looking for a color palet. With italic, bold and underline.

I would like a link to open up the palet, when clicking on a palet, it'll format the text in the textbox.

 

I don't know the best way to allow multiple colors. Either putting the code in (Also allows manual, rather than always having to click the button) or another method which I haven't thought of. I'd much prefer putting the code in. So that you can have multiple colors.

 

You then click submit. Now when displaying this information, I would like it to display in the colors, style; that they put in. That could be done with a BBCode function, or it can be done with str_replace() to replace the BBCode with HTML... although I would rather not do that method. I'd much prefer the BBCode function. Unless you have any good reasons for another method.

 

I have no experience with colors. So all help appreciated.

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/200442-text-formatting/
Share on other sites

Thanks litebearer. That'll come in handy for other bits on my site. I'm working from a textbox.

 

I found something and changed it. You input the string through a function parameter, and return it.

 

<?php  
function bbcode_format ($str) {  
    $str = htmlentities($str);  
  
    $bbcode = array(
            //Bold
                '/\[b\](.*?)\[\/b\]/is',
            //Italic
                '/\[i\](.*?)\[\/i\]/is',
            //Underline
                '/\[u\](.*?)\[\/u\]/is',
            //Font Family
                '/\[font\=(.*?)\](.*?)\[\/font\]/is',
            //Colors
                '/\[c\=(.*?)\](.*?)\[\/c\]/is',    
                //Code presentation  
            '/\[code\](.*?)\[\/code\]/is' 
                );  
  
    $htmlcode = array(  
            //Bold
                '<strong>$1</strong>',
            //Italic
                '<em>$1</em>',  
            //Underline
                '<u>$1</u>',  
            //Font Family
                '<span style="font-family: $1;">$2</span>',  
            //Colors
                '<span style="color: $1;">$2</span>',  
            //Code presentation 
            '<pre class="code">$1</pre>' 
                );  
  
    // Do simple BBCode's  
    $str = preg_replace ($bbcode, $htmlcode, $str);    
  
    return $str;  
}
?>

I haven't managed to test it yet. Would this enable multiple colors, etc.

For the top bit, where it has htmlentities, I'd like to do a str_replace of < and > so that HTML cannot be used. How would I do this?

str_replace('/\<(.*?)\>/is', '', $str)

Is that right?

Link to comment
https://forums.phpfreaks.com/topic/200442-text-formatting/#findComment-1051887
Share on other sites

As for the palette, I could use either css or javascript, to popup a div. From this div.. will have little square boxes with the color in... when you click them, it'll input the code into the textbox.

 

I would be able to get the div up, but I wouldn't be able to do the colour bit.

 

EDIT: I can use multiple colors from that function, although it doesn't remove <tags> ..

Any help with that?

Link to comment
https://forums.phpfreaks.com/topic/200442-text-formatting/#findComment-1051888
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.