supanoob Posted July 7, 2008 Share Posted July 7, 2008 ok so i have the following functions for my home made message board. <?php function make_post ($post_body) { $post_body=htmlspecialchars($post_body); $post_body=str_replace (array('[youtube]', '[/youtube]', '[', ']', 'url=', '/url', 'img=', 'post id=', '/post', 'font=', '/font', '[left]', '/left', '[center]', '/center', '[right]', '/right', '', '', ':scared:', '', ':roll:', ':mad:', ':love:', '', ':S'), array('<embed src="http://www.youtube.com/v/', '&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed>', '<', '>', 'a href=link_out.php?link=', '/a', 'img src=', 'a href=view_post.php?post_id=', '/a', 'font color=', '/font', 'p align=\"left\"', '/p', 'p align=\"center\"', '/p', 'p align=\"right\"', '/p', '<img src=\"/images/forum/wink.gif\">', '<img src=\"/images/forum/tongue.gif\">', '<img src=\"/images/forum/scared.gif\">', '<img src=\"/images/forum/sad.gif\">', '<img src=\"/images/forum/roll.gif\">', '<img src=\"/images/forum/mad.gif\">', '<img src=\"/images/forum/love.gif\">', '<img src=\"/images/forum/happy.gif\">', '<img src=\"/images/forum/confused.gif\">'), $post_body); return nl2br($post_body); } function make_post_reverse ($post_body) { $post_body=str_replace (array('<embed src="http://www.youtube.com/v/', '&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed>', '<img src="/images/forum/wink.gif">', '<img src="/images/forum/tongue.gif">', '<img src="/images/forum/scared.gif\">', '<img src=\"/images/forum/sad.gif">', '<img src="/images/forum/roll.gif">', '<img src="/images/forum/mad.gif">', '<img src="/images/forum/love.gif">', '<img src="/images/forum/happy.gif">', '<img src="/images/forum/confused.gif">', '<br />', '<', '>', 'a href=link_out.php?link=', '/a', 'img src=', 'a href=view_post.php?post_id=', '/a', 'font color=', '/font', 'p align=\"left\"', '/p', 'p align=\"center\"', '/p', 'p align=\"right\"', '/p'), array('[youtube]', '[/youtube]', '', '', ':scared:', '', ':roll:', ':mad:', ':love:', '', ':S', '', '[', ']', 'url=', '/url', 'img=', 'post id=', '/post', 'font=', '/font', 'left', '/left', 'center', '/center', 'right', '/right'), $post_body); return ($post_body); } ?> basically what is happening when someone makes a post everything works fine unless they use [ and ] in which case it turns them into < or > is there a better way to do the above without all cases of the [ and ] turning into < and > Link to comment https://forums.phpfreaks.com/topic/113647-functions-help/ Share on other sites More sharing options...
lemmin Posted July 7, 2008 Share Posted July 7, 2008 Take the check for "[" and "]" out? If your question is more complicated than that, I don't understand it. <?php function make_post ($post_body) { $post_body=htmlspecialchars($post_body); $post_body=str_replace (array('[youtube]', '[/youtube]', 'url=', '/url', 'img=', 'post id=', '/post', 'font=', '/font', '[left]', '/left', '[center]', '/center', '[right]', '/right', '', '', ':scared:', '', ':roll:', ':mad:', ':love:', '', ':S'), array('<embed src="http://www.youtube.com/v/', '&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed>', 'a href=link_out.php?link=', '/a', 'img src=', 'a href=view_post.php?post_id=', '/a', 'font color=', '/font', 'p align=\"left\"', '/p', 'p align=\"center\"', '/p', 'p align=\"right\"', '/p', '<img src=\"/images/forum/wink.gif\">', '<img src=\"/images/forum/tongue.gif\">', '<img src=\"/images/forum/scared.gif\">', '<img src=\"/images/forum/sad.gif\">', '<img src=\"/images/forum/roll.gif\">', '<img src=\"/images/forum/mad.gif\">', '<img src=\"/images/forum/love.gif\">', '<img src=\"/images/forum/happy.gif\">', '<img src=\"/images/forum/confused.gif\">'), $post_body); return nl2br($post_body); } function make_post_reverse ($post_body) { $post_body=str_replace (array('<embed src="http://www.youtube.com/v/', '&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed>', '<img src="/images/forum/wink.gif">', '<img src="/images/forum/tongue.gif">', '<img src="/images/forum/scared.gif\">', '<img src=\"/images/forum/sad.gif">', '<img src="/images/forum/roll.gif">', '<img src="/images/forum/mad.gif">', '<img src="/images/forum/love.gif">', '<img src="/images/forum/happy.gif">', '<img src="/images/forum/confused.gif">', '<br />', '<', '>', 'a href=link_out.php?link=', '/a', 'img src=', 'a href=view_post.php?post_id=', '/a', 'font color=', '/font', 'p align=\"left\"', '/p', 'p align=\"center\"', '/p', 'p align=\"right\"', '/p'), array('[youtube]', '[/youtube]', '', '', ':scared:', '', ':roll:', ':mad:', ':love:', '', ':S', '', '[', ']', 'url=', '/url', 'img=', 'post id=', '/post', 'font=', '/font', 'left', '/left', 'center', '/center', 'right', '/right'), $post_body); return ($post_body); } ?> That should do it. Link to comment https://forums.phpfreaks.com/topic/113647-functions-help/#findComment-584020 Share on other sites More sharing options...
supanoob Posted July 7, 2008 Author Share Posted July 7, 2008 Nah that didnt help, it didnt change any of the [ or ]'s Link to comment https://forums.phpfreaks.com/topic/113647-functions-help/#findComment-584024 Share on other sites More sharing options...
lemmin Posted July 7, 2008 Share Posted July 7, 2008 Ones like " " and " " will but lone ones shouldn't get changed. Link to comment https://forums.phpfreaks.com/topic/113647-functions-help/#findComment-584066 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.