dadamssg Posted August 7, 2009 Share Posted August 7, 2009 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 More sharing options...
The Little Guy Posted August 7, 2009 Share Posted August 7, 2009 This should help you out: http://beta.phpsnips.com/snippet.php?id=41 Link to comment https://forums.phpfreaks.com/topic/169164-replace-with-tags-help/#findComment-892588 Share on other sites More sharing options...
dadamssg Posted August 7, 2009 Author Share Posted August 7, 2009 i get this when i tried that snippet Warning: preg_replace() [function.preg-replace]: Compilation failed: missing terminating ] for character class at offset 15 in showthread.php on line 30 Link to comment https://forums.phpfreaks.com/topic/169164-replace-with-tags-help/#findComment-892592 Share on other sites More sharing options...
The Little Guy Posted August 7, 2009 Share Posted August 7, 2009 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); } Link to comment https://forums.phpfreaks.com/topic/169164-replace-with-tags-help/#findComment-892615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.