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.
<?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.
Comment