SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    I am looking the way to check a string to see if it contains illegal characters like ' and give an error. I am also not sure what characters are illegal in an MySQL database...

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are notconcerned whetehr the illegal characters are store din the database. You can use
    PHP Code:
    $data addslashes($data);
    $data htmlspecialchars($data); 
    That will take care of things like ' and the such.

    If you really don't want to allow them in a string you will need to use regular expressions

    PHP Code:
        $str"s-dfjghsd.fj.khs dj_ -hfsdj";
        print (
    ereg("^[-_ A-Za-z0-9\.]*$"$str)) ? "Doesn't include them" "Contains illegal chars"
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and I just replace $str with my variable?

  4. #4
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, just replace it with the name of your variable.


Bookmarks

Posting Permissions

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