function _AdvisingScreen::z__convert_bbcode_to_html

4.x _AdvisingScreen.php _AdvisingScreen::z__convert_bbcode_to_html($str)

Converts a string containing BBCode to the equivalent HTML.

Parameters

string $str:

Return value

string

File

classes/_AdvisingScreen.php, line 366

Class

_AdvisingScreen

Code

function z__convert_bbcode_to_html($str) 
 {
  // This will accept a string with BBcode tags in it,
  // and convert them to HTML tags.
  $str = str_replace("[b]", "<b>", $str);
  $str = str_replace("[/b]", "</b>", $str);

  $str = str_replace("[i]", "<i>", $str);
  $str = str_replace("[/i]", "</i>", $str);

  $str = str_replace("[u]", "<u>", $str);
  $str = str_replace("[/u]", "</u>", $str);

  $str = str_replace("[center]", "<center>", $str);
  $str = str_replace("[/center]", "</center>", $str);

  $str = str_replace("[ul]", "<ul>", $str);
  $str = str_replace("[/ul]", "</ul>", $str);

  $str = str_replace("[li]", "<li>", $str);
  $str = str_replace("[/li]", "</li>", $str);


  $str = str_replace("[br]", "<br>", $str);

  // convert more than 1 space into 2 hard spaces...
  $str = str_replace("  ", "&nbsp;&nbsp;", $str);


  // Check for colored text
  $str = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is", "<span style='color:$1;'>$2</span>", $str);

  // valid URL characters...
  $url_search_string = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
  // Check for a link...
  $str = preg_replace("(\[url\=([$url_search_string]*)\](.+?)\[/url\])", "<a href='$1' target='_blank' class='nounderline'>$2</a>", $str);
  // check for a link that does NOT load in a new window (URL2)
  $str = preg_replace("(\[url2\=([$url_search_string]*)\](.+?)\[/url2\])", "<a href='$1'>$2</a>", $str);
  // check for a link to a popup....
  $str = preg_replace("(\[popup\=([$url_search_string]*)\](.+?)\[/popup\])", "<a href='javascript: popupHelpWindow(\"$1\");' class='nounderline'>$2</a>", $str);
  // Images...  (looks like: [img]http://www.image.jpg[/img]
  //$str = preg_replace("(\[img\]([$url_search_string]*)\](.+?)\[/img\])", "<img src='$1' border='0'>", $str);

  // Images
  // [img]pathtoimage[/img]
  $str = preg_replace("/\[img\](.+?)\[\/img\]/", "<img src='$1' border='0'>", $str);

  // [img=widthxheight]image source[/img]
  $str = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", "<img src='$3' width='$1' height='$2' border='0'>", $str);



  return $str;
}