SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to check whether a character exists in a string?

    I display a textbox with the default value like '25%'.

    On submitting the form I want to check whether the posted value have % sign or not.
    [COLOR=SlateGray]
    Web Developer @ VeriQual

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    //type-checking comparison operator is necessary
    if (strpos($string'%') !== false) { 
      
    //PERCENT SIGN FOUND


  3. #3
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    PHP Code:
    //type-checking comparison operator is necessary
    if (strpos($string'%') !== false) { 
      
    //PERCENT SIGN FOUND

    Thx it worked,
    Now plz tell me how can I remove this cracter. 'cause I just want numbers.
    [COLOR=SlateGray]
    Web Developer @ VeriQual

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hmm.. try this.

    PHP Code:
    //replace all characters that are not numbers with nothing
    $string preg_replace("/[^0-9]/"""$string); 

  5. #5
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I just want to remove this '%' sign.....

    If the string is '25%'.
    Then I would like the out put like '25'
    [COLOR=SlateGray]
    Web Developer @ VeriQual

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $string str_replace('%'''$string); 

  7. #7
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx man!!

    Its solved........
    [COLOR=SlateGray]
    Web Developer @ VeriQual


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
  •