SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Is there any special charactesr or not?

    Code:
    $myVariable1 = "(";
    $myVariable2 = "a3bc123";
    $myVariable3 = "ze3>1fg";
    $myVariable4 = "35%cd:";

    In case of myVariable1, it has a special character only, i.e. (.

    In case of myVariable2, it has no special characters.

    In case of myVariable3, it has a special character, i.e. >.

    In case of myVariable4, it has some special characters, i.e. % and :.


    I like to make a condition about myVariables has any special characters, i.e. (,),$,>,>,:,;,,,%,/.
    Code:
    if ( $myVariables has any special characters )
    { echo "yes"; }
    else
    { echo "no;}
    In case of myVariable1, myVariable3, and myVariable4, it says "yes".
    and In case of myVariable2, it says "no".

    How can I check myVariables has special characters or not?

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Define 'special characters'. ctype_alnum classifies a space as a special character.

    Also your Locale setting will determine what ctype thinks constitutes a letter.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $myString = 'my text-1_2'; 
    $myValid = array('-', '_',' '); 
    
    if(ctype_alnum(str_replace($myValid, '', $myString))) { 
        echo '$myString consists of all English, digits, "-", or "_".'; 
    } 
    else
    {
    echo '$myString has any of special characters.';
    }
    The code above is good, I think, when English is the only language.
    But I like to make other languages, especially Korean language, are not recognized as special characters.


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
  •