Originally posted by arnage
View Post
Help! Quote Problem and Uppercase-Lowercase letter trick in php
Collapse
X
-
First thing is that every input needs to be sanitized, which means html symbols converted into their entities. That can be done with htmlentities() and single and double quotes are converted with htmlentities()'s flag ENT_QUOTES, and than both qoutes aren't gonna be escaped with adding \ backslash.Originally posted by Sifat3d View PostPlease take a look at this simple php code:
<?php
//string that needs to be customized
$text = $_POST['text'];
//placeholders array
$placeholders = array('some', 'random', 'simple', 'text');
//replace values array
$strangevals = array('die', 'in', 'this', 'tournament');
//strange string
$strangestr = str_replace($placeholders, $strangevals, $text);
echo "Weird text: ". $strangestr ;
?>
Example is:
Read details about it here: PHP: htmlentities - ManualPHP Code:$text = htmlentities($_POST['text'], ENT_QUOTES);
Second is done with one letter - i. "i" usualy means "insensetive case" and instead str_replace (string replace as is) use str_ireplace (string insensetive case raplce).
Example is:
PHP: str_replace - ManualPHP Code:$strangestr = str_ireplace($placeholders, $strangevals, $text);
Leave a comment:
-
"try to use stripslashes in this problem by adding
PHP Code:
$strangestr = stripslashes ( $strangestr );"
i didnt understand this part. Please explain.
Leave a comment:
-
try to use preg_replace,
also read about this
for modifiers reference
Added after 5 minutes:
try to use stripslashes in this problem by addingPHP Code://strange string
$strangestr = str_replace($placeholders, $strangevals, $text);
PHP Code:$strangestr = stripslashes($strangestr);
Last edited by kei_ki7; 20.08.11, 13:17.
Leave a comment:
-
the first thing isnt a problem i guess.. as this is an array and those words are individual there shouldn't any problem with the " " commas. it will catch the word from it.
and for the second thing you can use strtolower() function and check whether the input is replaceable or not.
like this:
PHP Code:$input = strtolower($_POST['input']);
$finalinput = str_replace("$input","$replacetxt",$finalinput); #make your own array or function for text.
#now the whole text will show in lowercase.
Leave a comment:
-
Help! Quote Problem and Uppercase-Lowercase letter trick in php
Please take a look at this simple php code:
<?php
//string that needs to be customized
$text = $_POST['text'];
//placeholders array
$placeholders = array('some', 'random', 'simple', 'text');
//replace values array
$strangevals = array('die', 'in', 'this', 'tournament');
//strange string
$strangestr = str_replace($placeholders, $strangevals, $text);
echo "Weird text: ". $strangestr ;
?>
This receives some text from a html input form, replaces the placeholder arrays with the strangevals arrays.
The problem is, when someone gives input for example: some random "burgers" and 'pizzas'
It results in: die in \"burgers"\ and \'pizza\'
How to solve the backward slash problem and show : die in "burgers" and 'pizza'
Please help me in this and provide sample code.
The Second thing:
when someone inputs -some- its replaced with -die- but when someone enters -Some- or -soME- or -sOMe- its not replaced.
I dont want to and cant create placeholders and strangevals for every single upper and lower case inputs like this!
Is there any way around this?
is there any way that if anyone inputs -some- or -SoMe- or -soME- or any other possible uppercase, lowercase combination its replaced with -die- ?
Please help me with this, im an newbie in php and really need help in this.
Leave a comment: