Search & Replace Function?

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Search & Replace Function?

    I have some textfield that users will enter data into on my web site
    and then I'll use php and write it to mysql - for security purposes,
    is there a function or way to make sure that they only enter in alpha
    and numeric data?

    Thanks...

    Ralph Freshour Guest

  2. Similar Questions and Discussions

    1. Search and replace
      I'm certain this has been asked 1000 times.. however ... I recently imported some data - all INTs ... from an excel sheet, but the damn thing...
    2. Search and Replace - Best Approach
      Hundreds of HTML file are generated by a program that includes in every file big chunks of comments, unused DHTML and Javascript functions. Always...
    3. Search and replace (super global replace)
      I am using the 30 day trail of acrobate professional....before I buy it I have a few questions.... 1) is there a "search and replace" function...
    4. search an replace
      Hi This scripts sucks in a 109mb file and i'm trying to do a search and replace on unxtime to the format from strftime. Which is working... ...
    5. search replace
      Hi , How do I search replace text in a file from a perl script. i.e. by opening the file in write mode and then do a search replace. I don't...
  3. #2

    Default Re: Search & Replace Function?

    Ralph Freshour wrote:
    > I have some textfield that users will enter data into on my web site
    > and then I'll use php and write it to mysql - for security purposes,
    > is there a function or way to make sure that they only enter in alpha
    > and numeric data?
    >
    > Thanks...
    yes, check all the characters.
    You can use a regular expression, or make your own little routine.

    In case of a regex, ask somebody else. I never took the time to study them,
    but know they are extremely powerfull once you get to know them.

    In case of your own little routine:
    just walk through the whole string and get a character at a time.
    Check if the character is in a string with 'acceptable characters'

    AcceptableCharacters = "abcdefghijklmnopqrstuvwxyz _1234567890-";

    use strlen to get the length of any string.
    use strrpos to find an occurence of any string in another string. It returns
    false when not found.

    use substr to get a character (or more) out of a string.

    You'll have to code the rest. :-)
    Good luck,
    Erwin
    Erwin Moller Guest

  4. #3

    Default Re: Search & Replace Function?


    On 16-Sep-2003, Ralph Freshour <ralph@primemail.com> wrote:
    > I have some textfield that users will enter data into on my web site
    > and then I'll use php and write it to mysql - for security purposes,
    > is there a function or way to make sure that they only enter in alpha
    > and numeric data?
    if (preg_match('/[^0-9a-z]/i',$input_string))
    // bad string
    else
    // good string

    --
    Tom Thackrey
    [url]www.creative-light.com[/url]
    Tom Thackrey Guest

  5. #4

    Default Re: Search & Replace Function?

    LOL,

    Go follow Tom's advise. :-)

    Erwin Moller Guest

  6. #5

    Default Re: Search & Replace Function?


    "Ralph Freshour" <ralph@primemail.com> wrote in message
    news:va7emv0seqvdutqp0qvomqemk413u1as61@4ax.com...
    > I have some textfield that users will enter data into on my web site
    > and then I'll use php and write it to mysql - for security purposes,
    > is there a function or way to make sure that they only enter in alpha
    > and numeric data?
    >
    > Thanks...
    >
    You could just use htmlentities() and/or htmlspecialchars() and/or
    addslashes() or eregi_replace() (though the latter depends on regular
    expressions and thats not the easiest to use).


    Randell D. Guest

  7. #6

    Default Re: Search & Replace Function?


    "Ralph Freshour" <ralph@primemail.com> wrote in message
    news:va7emv0seqvdutqp0qvomqemk413u1as61@4ax.com...
    > I have some textfield that users will enter data into on my web site
    > and then I'll use php and write it to mysql - for security purposes,
    > is there a function or way to make sure that they only enter in alpha
    > and numeric data?
    >
    > Thanks...
    >
    Try this

    <?
    $string="asbjhda12341dAsdf=a-!scda sd";
    preg_match_all ("([[:alnum:]]+)", $string,$regs);
    $c=implode("",$regs[0]);
    print("$string = $c");
    ?>

    The output should be

    asbjhda12341dAsdf=a-!scda sd = asbjhda12341dAsdfascdasd

    Note - it literally only returns alpha numeric - No periods, spaces,
    apostraphes or anything else...


    Randell D. Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139