Help! Quote Problem and Uppercase-Lowercase letter trick in php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sifat3d
    replied
    Originally posted by arnage View Post
    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.
    Example is:
    PHP Code:
    $text = htmlentities($_POST['text'], ENT_QUOTES); 
    Read details about it here: PHP: htmlentities - Manual
    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 Code:
    $strangestr = str_ireplace($placeholders, $strangevals, $text); 
    PHP: str_replace - Manual
    thanks that really helped.

    Leave a comment:


  • arnage
    replied
    Originally posted by Sifat3d View Post
    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 ;
    ?>
    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.
    Example is:
    PHP Code:
    $text = htmlentities($_POST['text'], ENT_QUOTES); 
    Read details about it here: PHP: htmlentities - Manual
    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 Code:
    $strangestr = str_ireplace($placeholders, $strangevals, $text); 
    PHP: str_replace - Manual

    Leave a comment:


  • Sifat3d
    replied
    "try to use stripslashes in this problem by adding
    PHP Code:
    $strangestr = stripslashes ( $strangestr );"
    i didnt understand this part. Please explain.

    Leave a comment:


  • kei_ki7
    replied
    try to use preg_replace,

    also read about this


    for modifiers reference

    Added after 5 minutes:

    PHP Code:
    //strange string
    $strangestr = str_replace($placeholders, $strangevals, $text); 
    try to use stripslashes in this problem by adding
    PHP Code:
    $strangestr = stripslashes($strangestr); 
    Last edited by kei_ki7; 20.08.11, 13:17.

    Leave a comment:


  • khan
    replied
    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.
Working...
X