simple question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
red wolf
Forum Newbie
Posts: 11
Joined: Sun Feb 19, 2012 4:38 am

simple question

Post by red wolf »

i have form the the user can enter his own comment by post form.
i have file comment.php that working on this file.
i want that the file will excute all option to right html/php/mysql and other tags.
i mean that its will not be possible to write in comment code that will do any script.
somebody have ideas for me please?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: simple question

Post by Celauran »

Do you mean strip_tags()?
red wolf
Forum Newbie
Posts: 11
Joined: Sun Feb 19, 2012 4:38 am

Re: simple question

Post by red wolf »

Man.
THANK YOU VERY MUCH!
Best Helping Board in the world!
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: simple question

Post by phphelpme »

Why not use something like my code below which will give you choice of what is accepted or not etc

Code: Select all

$string = "This IS a STring that has Ma£NY different cases, and even (including& characTers that you migHT not WANT To AppeaR! %^&%*&&^%^%^%£^*)*";

function replace($replace) { // CREATES THE REPLACE FUNCTION TO CALL ANYTIME
$replace = strtolower($replace); // MAKE ALL CHARACTERS LOWERCASE
$disallowed = array("!", "£", "$", "%", "^", "&", "*", "(", ")", "_", "+", "-", "=", "{", "}", "[", "]", ":", ";", "@", "'", "~", "#", "<", ",", ">", ".", "?", "/", "|", "`", "¬", "\\"); // DISALLOWED CHARACTERS
$stripped = str_replace($disallowed, "", $replace); // REPLACE DISALLOWED CHARACTERS WITH "" I.E. NOTHING!
return $stripped;
}

$string_result = replace($string); // CALLS THE REPLACE FUNCTION ON THE VARIABLE $STRING

echo $string_result;

// RESULT BEING: this is a string that has many different cases and even including characters that you might not want to appear
This way you can choose which characters you want to allow and which ones you do not. It is not exactly what you are looking for but will give you a great tool that will give you more control over what is accepted or not.

Best wishes
Last edited by phphelpme on Wed Mar 28, 2012 4:29 pm, edited 1 time in total.
red wolf
Forum Newbie
Posts: 11
Joined: Sun Feb 19, 2012 4:38 am

Re: simple question

Post by red wolf »

nice!
thanks!
Post Reply