hello! for the newline we have the fuction nl2br() but what about BOLD text.. underline or italic ?! is there a way to convert that rich text in to HTML? bold into <b> bold </b>... ??

Member Avatar for diafol

Firstly, I'd use <strong> as opposed to <b>, <em> as opposed to <i>. I'd never use an underline as users may confuse this with a hyperlink.

How are you encoding bold type in your rich text? ARe you using [ B ][ / B ]? BBCode??

How are you generating rich text?

it's not cms or BB, i get the text normaly from mysql database in utf-8 encoding.. mysql save it as a rich text, i hope, i'm not sure about that..

i know all about HTML and replacing characters in php.. all i need to know is the "char" for bold, underline and italic text.. for newline are "\n\r" right? in php.. but what about bold, underline and italic??

Member Avatar for diafol

SOrry I'm none the wiser. ARe you producing the rich text (e.g. by a wysiwyg editor) and then trying to store it in mysql DB? OR, are you using some mysql jiggery-pokery {"...mysql save it as a rich text"} to transform the string as it inserts/updates?

I wasn't aware that there was a character for bold etc. Could you show an example of your richtext containing some bold parts?

PHP outputs plain text in the main. You can format it with html etc with parsers as you know {"i know all about HTML and replacing characters in php"}. I don't understand what you're trying to achieve here. THe only thing I can think of is use placeholders, like BBCode for your 'richtext' and parse back to html.

noo.. the text is saved by html forms.. with php query insert or update, and the BB code are replacing the rich text :| it's what i need to do! to replace the rich text with html not BBcode.... why using placeholders when i can use directly HTML codes?.. all i need to know is how to replace the bold from the rich text format (not .rtf document!) just the code that makes the text bold in microsoft word for example.. is invisible! like the newline \n but is replaced by nl2br() function to <br>! what about bold? is there a function to replace bold to <b>bold</b>

damm.. nobody understand my english?:D i don't need a text editor.. i just want to ECHO from MySQL database my text on a website! and that text contains already bold but on the page is not bolded and i need to add <b>bold</b> by replacing the code that makes the text bolded on windows ! for example it could be \b i want to replace \b with <b>.. (but i don't know the real character used to make text bold is not \b) anybody know what's that char ???

that text is passed by html forms to php and saved in to mysql database


i used: echo nl2br($text); just for "newline" (\n\r) from the text! but for bold what i need to do?! is there a function?

Member Avatar for diafol

You're the one passing rich text. Where the hell is this rich text coming from??

If you're pasting raw rtf code:

"Help me please" would be

Help me \b please\b0

Parse with

$string = str_replace("\b0","</strong>",$string);
$string = str_replace("\b","<strong>",$string);

in that order.

I don't know if this is what you're after.

it comes from mysql database, but i want to modify it after.. or before if is needed when the form is submited, the text is copied with all his properties in pasted in to the form textarea

Member Avatar for diafol

The data in the mysql database had to come from somewhere right?

You state the text is copied into the textarea. From where? A word document or a wordpad doc? I don't think that \b is copied to the textarea - I may be wrong. Just newlines. Textareas are supposed to contain just plain text. I believe the newlines can be translated to ascii, whereas \b codes cannot. I may be well off track here though.

This is an example of rtf taken from wordpad:

{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.21.2508;}\viewkind4\uc1\pard\f0\fs20 Help me \b please\b0\par
}

To get that I opened an rtf file in Notepad. I doubt you'd want that stored in your DB though. Parsing all that would be a nightmare, although doubtless somebody out there has done some work on it.

I would suggest using a wysiwyg editor like CKEditor so that you can paste rich text into it directly and get the generated html that way.

You could possibly with some jiggery-pokery, take the DB data and place it into the editor (using js) and save the output (via ajax).

Before you start saying "but my data's in the DB" - I know - but how did it get there in that format?

same problem is mine.read the problem carefully: "Suppose I will write 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' in a textarea on a webpage(like a blog with smileys) and I want that text as bold,italic or increased size and want to store in mysql database.and then I want to show that text on a webpage from database as same bold,italic,line break,smiley.and I want 'if the length of a single line exceeds the width of html table,then that single line will be split to keep the column width fixed.'"....

now plz tell me how can I do those.

Can you give us an exemple of what the data stored in your DB looks like?

ok,my data is "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" in mysql database.and I want to show that data in a table whose column width is 50.I can't do this cause when I show that data in that width column then always the column width increases automatically to fit the content.I tried by making the column width fixed,but then I see that the column width not increased but the content crosses the column border.I want to do that "if the data width is larger than the column width of the table then the long continuous data will be broken and one part will be shown in a line and the rest part of data will be shown in next line (in same table cell) like textarea".how can I do that in a table cell instead of using textarea ?

use wordwrap:

<?php echo wordwrap(nl2br($your_message), 50, "<br>\n", TRUE); ?>

Disclaimer: I'm working for this company.

Hi! May you try to use the library for this? "RTF to HTML DLL .Net" allows to convert from rtf to html easy. This component doesn't require MS Office or any other word-processor. Here you can find free trial version or try online converting.
The component supports full text formatting (bold, italic, underline, double underline, strike, superscript, subscript). So you can solve your problem by using "RTF to HTML".

Sample code for the converting:

How to convert RTF to HTML in PHP:

1. Add the SautinSoft.RtfToHtml.dll to the GAC, launch:
gacutil.exe /i SautinSoft.RtfToHtml.dll
2. Add the Assembly to the Registry, launch:
Regasm.exe SautinSoft.RtfToHtml.dll /tlb:SautinSoft.RtfToHtml.tlb

    <?php
    $r = new COM("SautinSoft.RtfToHtml");

    /* Convert RTF file to HTML string and show it in browser */
    $html = $r->ConvertFileToString("d:\\Source.rtf");

    if ($html=="")
        print("Can't find input RTF. Please check input path");
    else
        print($html);
?>

This only works when using PHP on Windows servers...

You can run .Net components for PHP on Linux. More about this you can see HERE, for example :)

/Jane/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.