Jump to content

Recommended Posts

ok I want to create bb codes,
I found this little script. but it doesnt support images.

[code]          $string = $_CONTENT['TUT_CONTENT'];
$bb_replace = array ('/(\[[Bb]\])(.+)(\[\/[Bb]\])/','/(\[url=)(.+)(\])(.+)(\[\/url\])/');
$bb_replacements = array ('<b>\\2</b>','<a href="\\2">\\4</a>');
$string = preg_replace($bb_replace, $bb_replacements, $string);
print $string;[/code]

Ive already installed it ant it works fine, (except the image part)

[code]$bb_replace = array ('/(\[[Bb]\])(.+)(\[\/[Bb]\])/','/(\[url=)(.+)(\])(.+)(\[\/url\])/','/(\[img])(.+)(\[\/img\]);
$bb_replacements = array ('<b>\\2</b>','<a href="\\2">\\4</a>','<img scr="\\2">');[/code]

would something like that work?

if so, can you please explain why, because I have no idea what those numbers mean!

Thanks!

edit:

also when i enter something in the text field and then hit submit it enters almost everything (in the text field) to the database.
Im having touble with line breaks though.

say if you hit enter 3 times on this forum, then in the post you would see 3 lines spaces.


How do i do the same thing with my text box?
Link to comment
https://forums.phpfreaks.com/topic/11100-creating-bb-code/
Share on other sites

Change your code to this:
[code]$bb_replace = array ('/(\[[Bb]\])(.+)(\[\/[Bb]\])/','/(\[url=)(.+)(\])(.+)(\[\/url\])/','/(\[img\])(.+)(\[\/img\]);
$bb_replacements = array ('<b>\\2</b>','<a href="\\2">\\4</a>','<img scr="\\2">');[/code]

And about line breaks. The line breaks are being inserted into the database, but the actuall problem is the web browser. Web browsers ignore white spacecharacters, such as newlines, carriage returns etc. To solve this you'll want to use a function called nl2br. Now use this function when you are retrireving data out of of the database like so:
$var = nl2br($row['fieldnamehere']);

What this will now do is convert newlines/carriage returns into their html equivilant the linebreak (< br />) tag.
Link to comment
https://forums.phpfreaks.com/topic/11100-creating-bb-code/#findComment-41519
Share on other sites

Thanks for the help, but it is still not working! :S

this is my code that displays the info

[code]
<td>
          <br>
          <?
          $string = $tut_withlines;
$bb_replace = array ('/(\[[Bb]\])(.+)(\[\/[Bb]\])/','/(\[url=)(.+)(\])(.+)(\[\/url\])/','/(\[img\])(.+)(\[\/img\])');
$bb_replacements = array ('<b>\\2</b>','<a href="\\2">\\4</a>','<img scr="\\2">');
$string = preg_replace($bb_replace, $bb_replacements, $string);
print $string;
                 
           ?>
          <br>
          <br>
          <br>
          Tutorial By: <a href = "userinfo.php?user=<?= $_CONTENT['AUTHOR'] ?>"><?= $_CONTENT['AUTHOR'] ?></a>
          <br>
          <br></td>
[/code]

this is the bb code writen in the database,
[code][img]http://img220.imageshack.us/img220/6554/button1mv.gif[/img][/code]
and it should work like so
[img src=\"http://img220.imageshack.us/img220/6554/button1mv.gif\" border=\"0\" alt=\"IPB Image\" /]

but its showing up straight text.


as for the nl2br

I got it working fine!

Thanks for that! :)
Link to comment
https://forums.phpfreaks.com/topic/11100-creating-bb-code/#findComment-41536
Share on other sites

try this:
[code]$bb_replace = array ('/(\[[Bb]\])(.+)(\[\/[Bb]\])/',
                     '/(\[url=)(.+)(\])(.+)(\[\/url\])/',
                     '/(\[img\])(.+)(\[\/img\])/');

$bb_replacements = array ('<b>\\2</b>',
                          '<a href="\\2">\\4</a>',
                          '<img scr="\\2" />');[/code]

basically you forgot to add the ending delimiter which is the backslash '/'
Link to comment
https://forums.phpfreaks.com/topic/11100-creating-bb-code/#findComment-41546
Share on other sites

Thanks, works like a *charm*
Im getting a broken image though!

[code]<img scr="http://img220.imageshack.us/img220/6554/button1mv.gif" />[/code]

That was taken form the source code of the page 9in the browser)
The image still works, do you see anything wrong with the code?
I dont

would it have anything to do with the dementions not being there? I wouldnt think so, but im a noob!

is there a way php can find the demetions of it with out the user having to enter them?
Link to comment
https://forums.phpfreaks.com/topic/11100-creating-bb-code/#findComment-41548
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.