Jump to content

Functions Help


supanoob

Recommended Posts

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

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

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.