Not sure if this is PHP, but...
Moderator: General Moderators
-
ibanez270dx
- Forum Commoner
- Posts: 74
- Joined: Thu Jul 27, 2006 12:06 pm
- Location: Everywhere, California
Not sure if this is PHP, but...
Hi,
I have an online page editor program that needs to be able to support images wherever the user specifies. In perticular, the user will be dealing with a textarea box in which they can enter plain text, but I need some sort of tag that would call the image where the user specifies in the textbox. For example, in the textarea box, the user can put something like this:
This is my page. Here is a picture of me [img]me.jpg[/img]
The pictures would be uploaded beforehand and stored in folder images/ from the current directory. I guess what I need is something like here on the forums when you a post a topic or reply. I'd like a button on top that would insert the tags... How can I do this?
Thanks,
- Jeff
I have an online page editor program that needs to be able to support images wherever the user specifies. In perticular, the user will be dealing with a textarea box in which they can enter plain text, but I need some sort of tag that would call the image where the user specifies in the textbox. For example, in the textarea box, the user can put something like this:
This is my page. Here is a picture of me [img]me.jpg[/img]
The pictures would be uploaded beforehand and stored in folder images/ from the current directory. I guess what I need is something like here on the forums when you a post a topic or reply. I'd like a button on top that would insert the tags... How can I do this?
Thanks,
- Jeff
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
You can put a javascript-driven WYSIWYG in the textarea, but that will actually insert html into the page instead of bbcode like you asked for. TinyMCE Editor and FCKEditor (that's fck-- no "u" in there
) are the only ones I know of.
To use bbcode, I think you have to write a parser in php... I'll leave that one up to somebody else to answer.
To use bbcode, I think you have to write a parser in php... I'll leave that one up to somebody else to answer.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Firstly you would need the button itself, that's a bit of HTML and then you need to attach from JS to it for appending the textarea etc.
Then when the textarea is submitted you need to use PHP to find the tag and perform whatever action based upon it.
Here's a bit of JS that may helpuntested. This isn't that greater code but meh.
Then when the textarea is submitted you need to use PHP to find the tag and perform whatever action based upon it.
Here's a bit of JS that may help
Code: Select all
<button type="button" onclick="appendWithImgTag(this)">Add Img</button>
<script type="text/javascript">
function appendWithImgTag(this)
{
var textarea = document.getElementById('the id here');
if (!textarea) throw 'Not found';
if(appendWithImgTag.open) {
textarea.value += '[img]';
} else {
textarea.value += '[/img]';
}
appendWithImgTag.open = !appendWithImgTag.open;
}
appendWithImgTag.open = true;
</script>
-
ibanez270dx
- Forum Commoner
- Posts: 74
- Joined: Thu Jul 27, 2006 12:06 pm
- Location: Everywhere, California
I think I'd be able to do it using PHP... couldn't I use the str_replace() function? I just don't know how I can get the text in between the tags to a variable... I was thinking in this way:
where $name is the content between the tags...
would something like this be workable?
where $name is the content between the tags...
Code: Select all
$content1 = str_replace('[img]', '<img src=images/$name>', $textarea_content);
$content2 = str_replace('[/img]', ' ', $content1);- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Code: Select all
<img src=images/$name>Seriously, it would make me very happy
Code: Select all
<img src="images/$name" alt="" />-
ibanez270dx
- Forum Commoner
- Posts: 74
- Joined: Thu Jul 27, 2006 12:06 pm
- Location: Everywhere, California
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
preg_match(). Or you can download phpBB and check out their bbcode.php page for how they handle bbcode.
Another nice bbCode parser is the one on Corz Blog. It is a little rough on the code to test, but once you get it, it is pretty nice.
Another nice bbCode parser is the one on Corz Blog. It is a little rough on the code to test, but once you get it, it is pretty nice.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
ibanez270dx
- Forum Commoner
- Posts: 74
- Joined: Thu Jul 27, 2006 12:06 pm
- Location: Everywhere, California
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
