Documentation

TxtToHTML

string
TxtToHTML(
 string text,
 bool make_url = true,
 int max_string = 0,
 string quote_tag_enabled = "N",
 string not_convert_amp = "Y",
 string code_tag_enabled = "N",
 string biu_tags_enabled = "N",
 string quote_table_class = "quotetable",
 string quote_head_class = "tdquotehead",
 string quote_body_class = "tdquote",
 string code_table_class = "codetable",
 string code_head_class = "tdcodehead",
 string code_body_class = "tdcodebody",
 string code_textarea_class = "codetextarea",
 string link_class = "txttohtmllink",
 array  event = array()
);

The function converts plain text to HTML formatted text.

Function parameters

ParameterDescription
text Original text.
make_url If true, strings containing web addresses (http://... or mailto:) will be converted to HTML links.
Optional; the default value is true.
max_string Maximum length of each word. All words whose length exceeds this value is split with spaces. A value of "0" disables splitting.
Optional; the default value is "0".
quote_tag_enabled If "Y", a special tag ... will be converted to the HTML table (frames the quote in border).
Optional; the default value is "N".
not_convert_amp If "Y", ampersand symbols "&" will not be converted to "&".
Optional; the default value is "Y".
code_tag_enabled If "Y", a special tag <CODE>...</CODE> will be converted to the HTML "textarea" element in table (frames the code in border and displays it in the "textarea" tag).
Optional; the default value is "N".
biu_tags_enabled If "Y", special tags<b>...</b>, <i>...</i>, <u>...</u> are converted to corresponding HTML tags.
quote_table_class CSS class for the () table. (<quote>).
Optional parameter. Optional; the default value is "quotetable".
quote_head_class CSS class for the first cell (TD) of the "quote" table (<quote>).
Optional; the default value is "tdquotehead".
quote_body_class CSS class for the second cell (TD) of the "quote" table (<quote>):
<table class="quote_table_class">
    <tr>
         <td class="quote_head_class"> ... 
         </td>
    </tr>
    <tr>
         <td class="quote_body_class"> ... 
         </td>
    </tr>
</table>
Optional parameter. By default - "tdquote".
code_table_class CSS class for the "code" table (<code>).
Optional; the default value is "codetable".
code_head_class CSS class for the first cell of the "code" table (<code>).
Optional; the default value is "tdcodehead".
code_body_class CSS class for the second cell of the "code" table (<code>).
Optional; the default value is "tdcodebody".
code_textarea_class CSS class for the "textarea" tag in the "code" table (<code>):
<table class="code_table_class">
    <tr>
         <td class="code_head_class"> ... </td>
    </tr>
    <tr>
         <td class="code_body_class">
             <textarea class="code_textarea_class"> ... 
             </textarea>
         </td>
    </tr>
</table>
Optional parameter. By default - "codetextarea".
link_class CSS for links:
<a class="link_class"> ... </a>
Optional parameter. By default - "txttohtmllink".
event This array can be used to pass the event type identifiers to register when a HTML link is clicked. This parameter is only effective if make_url is true..

The following keys are possible:
  • EVENT1 - event type identifier - event1;
  • EVENT2 - event type identifier - event2;
  • EVENT3 - event type identifier - event3;
  • SCRIPT - path to the script file performing registration and redirect. The path is specified relative to the root.

See Also

  • [link=90014]HTMLToTxt[/link]

Example


Call:

$text = "
text text text text
text text text text 
longwordlongwordlongwordlon
<code>code code code</code>
<quote>quote quote quote</quote>
<b>highlighted text</b>
<i>cursive</i>
<u>underlined</u>
ссылка: http://www.bitrix24.com
email: support@bitrix24.com
";
echo TxtToHTML(
	$text, 
	true, 
	20, 
	"Y", 
	"N", 
	"Y", 
	"Y", 
	"quotetable", 
	"tdquotehead", 
	"tdquote",
	"codetable",
	"tdcodehead",
	"tdcodebody",
	"codetextarea"
	);


Result:

text text text text <br>
text text text text <br>
longwordlongwordlong word<br>   
<table class='codetable'>
  <tr>
    <td class='tdcodehead'>Код</td>
  </tr>
  <tr>
    <td class='tdcodebody'>
      <textarea class='codetextarea' contentEditable=false cols=60 rows=15 wrap=virtual>code code code</textarea></td>
    </tr>
</table><br>
<table class='quotetable' width='95%' border='0' cellpadding='3' cellspacing='1'>
  <tr>
    <td class='tdquotehead'>Quote</td>
  </tr>
  <tr>
    <td class='tdquote'>quote quote quote</td>
  </tr>
</table><br>
<b>highlighted text</b><br>
<i>cursive</i><br>
<u>underlined</u><br>
ссылка: <a class="txttohtmllink" href="http://www.bitrix24.com">http://www.bitrix24.com</a><br>
email: <a class="txttohtmllink" href="mailto:support@bitrix24.com">support@bitrix24.com</a>


CSS (it must be preliminarily connected before calling the function):

.quotetable, .codetable {width:90%}

.quotetable .tdquotehead, 
.quotetable .tdquote, 
.codetable  .tdcodehead,
.codetable  .tdcodebody,
.codetextarea {padding: 2px; font-family: Arial; font-size:12px; color:#000000}

.quotetable .tdquotehead, 
.codetable  .tdcodehead {font-weight:bold}

.quotetable .tdquote, 
.codetable  .tdcodebody {border: 1px solid Black}

.quotetable .tdquotehead, 
.quotetable .tdquote, 
.codetable  .tdcodehead,
.codetable  .tdcodebody,
.codetextarea {background-color: #FFFFFF}

.codetextarea {
  border: solid 0px; 
  width: 100%;
  overflow: auto;
  scrollbar-shadow-color: #000000; 
  scrollbar-arrow-color:  #000000; 
  scrollbar-base-color:   #000000}

.codetextarea {
  scrollbar-face-color:       #FFFFFF; 
  scrollbar-highlight-color:  #FFFFFF; 
  scrollbar-track-color:      #FFFFFF; 
  scrollbar-darkshadow-color: #FFFFFF}


Visual presentation (the presentation of what we will see onscreen):

text text text text
text text text text
longwordlongwordlongword
Code.

Quote.
quote quote quote.

highlighted text текст
cursive
underlined
link: http://www.bitrix24.com
email: support@bitrix24.com


© «Bitrix24», 2001-2024
Up