Jump to content

Recommended Posts

I want do exactly what this forum does...as in you can write [ code ] whatever [ / code] and it will replace that with other tags wrapped around "whatever". How do i write a function to do this? i really want to have an image tag. So it would be something like [ img ]url-to-the-image[ /img ]. (Of course i don't want the spaces in the tags...not sure how this forum with interpret it) Then when you write those tags it would replace it with html image tags. how the heck would i write this function? help would be GREATLY appreciated

Link to comment
https://forums.phpfreaks.com/topic/169164-replace-with-tags-help/
Share on other sites

oops try this:

function text2bbc($text){
$find = array(
	'~\[b\](.*?)\[/b\]~s',
	'~\[i\](.*?)\[/i\]~s',
	'~\[u\](.*?)\[/u\]~s',
	'~\[size=(.*?)\](.*?)\[/size\]~s',
	'~\[color=(.*?)\](.*?)\[/color\]~s'
);
$replace = array(
	'<b>$1</b>',
	'<i>$1</i>',
	'<span style="text-decoration:underline;">$1</span>',
	'<span style="font-size:$1px;">$2</span>',
	'<span style="color:$1;">$2</span>'
);
return preg_replace($find,$replace,$text);
}

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.