Jump to content

replace with tags help


dadamssg

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);
}

Archived

This topic is now archived and is closed to further replies.

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