Modifying PHP Code to Automatically Insert Image

  • Thread starter Thread starter Jameson
  • Start date Start date
  • Tags Tags
    Php
Click For Summary

Discussion Overview

The discussion revolves around modifying PHP code in a phpBB forum to automatically insert an image tag when specific text is typed. Participants explore the technical aspects of implementing this feature, including identifying the relevant files and understanding the syntax required for custom BB code.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • One participant seeks guidance on how to modify the phpBB code to automatically insert an image tag based on user input.
  • Another suggests finding the script that handles existing BB codes and adding new tags, mentioning the need for tracing through the post display PHP.
  • A participant expresses uncertainty about PHP syntax and the complexity of the code.
  • One user identifies the file bbcode.php as relevant but finds it tedious to navigate.
  • Another participant offers a tutorial link that could assist in the coding process.
  • There is a request for clarification on the logic needed to implement the desired functionality.
  • A participant expresses frustration at the lack of PHP knowledge among others in the thread.
  • One user indicates they have received the necessary code from another source, concluding their need for assistance.

Areas of Agreement / Disagreement

The discussion features a mix of uncertainty and varying levels of familiarity with PHP among participants. There is no consensus on a specific solution, as some participants are still seeking clarity while others have found alternative resources.

Contextual Notes

Participants express varying levels of comfort with PHP, and there are indications of missing details in the tutorial referenced, which may affect understanding. The discussion does not resolve the technical challenges presented.

Jameson
Insights Author
Gold Member
MHB
Messages
4,533
Reaction score
13
I have a phpBB forum and I'm trying to edit some code so that whenever someone types in [math]Some code[/math] it automatically inserts <img src="mysite.com/cgi-bin-mimetex.cgi?Some code">. This will save people the trouble of typing in all of the extra stuff. It seems rather simple but I have no idea how to go about it.

Any ideas?
 
Computer science news on Phys.org
I would imagine the cleanest way to do this is find the script that handles the other BB codes, the add the few new tags of your own using similar syntax.

This is going to require you to do some tracing from the post display php, unless someone with experience would kindly pinpoint the file :P

With Invision Boards which I use on my site, there is a file in the /lib/ directory post_parser.php, which contains a

//-----------------------------------------
// Custom BB code
//-----------------------------------------

section. I could imagine phpBB having something similar.
 
Last edited:
That's what I was thinking, but I'm not familiar with PHP and the syntax is very meticulous.
 
I know the file... and I'm looking at the code right now. I'm just not sure how to recreate it. There are many parts.

Here's some of it:

Code:
function prepare_bbcode_template($bbcode_tpl)
{
	global $lang;

	$bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']);

	$bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']);

	$bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']);

	$bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']);

I can see where certain parts fit in, but I couldn't write it myself.
 
I did some searches and it says that phpBB's code is in bbcode.php. A bit tedious to go through... that's why I didn't choose to do programming as a major >.<

However, while searching I did come across this site, which is probably the best direct help you could probably get.

http://www.phpbbhacks.com/forums/archive/o_t/t_54124/making_your_custom_bbcode.html
 
Last edited by a moderator:
Hey thanks a bunch! That's a great tutorial. I'll let you know if I get something useful written.
 
Hmmm... reading this through, I'm having trouble following it. I need something to the evquivalent of this.

When $text = [math] then copy until $$
and insert <img src="mysite.com/cgi-bin/mimetex.cgi?$text">

That's not in any language of course, but the general logic of it. I tried reading that tutorial, and it starts out nicely, but kind of stops describing.
 
No one here knows PHP? :(
 
Further explain this and I'll give you the instructions
Do you mean when someone types [math]text here[/math] it inserts <img src="mysite.com/cgi-bin/memetex.cgi?text%20here">

If so I'll give the directions ASAP
 
  • #10
Thanks for the help, but I already got the code from someone else. Appreciate it.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 4 ·
Replies
4
Views
7K
Replies
10
Views
6K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 23 ·
Replies
23
Views
4K
  • · Replies 1 ·
Replies
1
Views
8K