Page 1 of 1

Using vb code with php

Posted: Thu Sep 18, 2003 3:05 am
by cypher
Every forum I have run across uses vb code. For those who don't know what this is ... it's all those:Bold, Italic, Underline, Quote ... etc ... you see above where you type to respond.

I have javascript that does all the inserting for the vb code into the text box, but I am having trouble with one perticular part ... I was hoping that someone could help me here.

This is what I am using for the bold, italic, and underline, which work and are fairly easy to understand and use:

Code: Select all

<?
          $message = str_replace("&#1111;b]", "<b>", $message);
          $message = str_replace("&#1111;/b]", "</b>", $message);
          $message = str_replace("&#1111;i]", "<i>", $message);
          $message = str_replace("&#1111;/i]", "</i>", $message);
          $message = str_replace("&#1111;u]", "<u>", $message);
          $message = str_replace("&#1111;/u]", "</u>", $message);

          return $message;
?>
The major issue I am having is ... when someone wants to make their image vb code have a url attached to it... how would you do this in vb code?

this is what a friend sent me ... but it does not work, and below the example, is how it displays:

Code: Select all

<?
          $patterns = array();
          $replacements = array();
          $patterns&#1111;] = "#\&#1111;url\](&#1111;a-z]+?://)&#123;1&#125;(.*?)\&#1111;/url\]#si";
          $replacements&#1111;] = '<a href="\1\2" target="_blank">\1\2</a>';
          $patterns&#1111;] = "#\&#1111;url\](.*?)\&#1111;/url\]#si";
          $replacements&#1111;] = '<a href="http://\1" target="_blank">\1</a>';

          $message = preg_replace($patterns, $replacements, $message);

          $message = preg_replace("'\&#1111;img\](&#1111;a-z]+?://)&#123;1&#125;(.+?)\&#1111;/img\]'i", "<img src="$1$2" border="0" />", $message);
          $message = preg_replace("'\&#1111;img=(&#1111;0-9]&#123;1,3&#125;)x(&#1111;0-9]&#123;1,3&#125;)\](&#1111;a-z]+?://)&#123;1&#125;(.+?)\&#1111;/img\]'i", "<img src="$3$4" border="0" width="$1" height="$2" />", $message);

          return $message;
?>
And here's what that last part outputs

Code: Select all

<a href="http://www.1234.com/<img src="http://www.1234.com/image.gif" border="0" />" target="_blank">http://www.1234.com/<img src="http://www.1234.com/" border="0" /></a>
Please look closely!

If you can help me, I would like to thank you ahead of time.

thanks
Cypher.

Posted: Thu Sep 18, 2003 2:20 pm
by m3rajk
i prefer preg to ereg

not exactly a fix, but it may work better for you

Code: Select all

function codeparse($precode){ # removes html then parses the forumcode
  /* *******************************************************************************************
  ********  this function is to be done on text that has already had html, slashes and  ********
  ********  extra space REMOVED prior to being sent through this.                       ********
  ******************************************************************************************* */
  $codeexempt=array(); # array for code exempt blocks
    
  # make replacements
  
 /* jumping so that i just give you what you're interested in */
  # urls
  $postcode=preg_replace('|\[url](?U)(.*)\[/url]|i', '<a href="\1" target="_blank">\1</a>', $postcode);
 
  # images
  $postcode=preg_replace('|\[img=([^]]*?)]|i', '<img src="\1" border="0">', $postcode);
 
}

Posted: Fri Sep 19, 2003 3:38 am
by cypher
I guess what I am going to have to do is ... download a forum such as phpbb or something, and find out how they did their vb coding ...

I will post a result here, when I find it :)

Cypher

Posted: Fri Sep 19, 2003 3:58 am
by volka
there are numerous class for ubbcode-processing
e.g. http://www.phpclasses.org/mirrors.html? ... 2F818.html