Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts

    custom function problems...

    What's the difference in the following functions other than 'Exists1' looks for a pos and 'Exists' looks for the string?
    Code:
    //--- checks for text within a string ---//
    function TextExists1($v,$t) {
       return (strpos( strtolower($v),$t) !== false )?1:0;
    }
    
    //--- checks for text within a string ---//
    function TextExists($v,$t) {
       return ( strstr(strtolower($t), strtolower($v) ) !== false ) ? 1:0;
    }
    
    
    
    
    Post Validation:
    //----- Valid WebsiteUrl? -----//
    if( TextExists($key,'websiteurl') ){
       if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $value)) {
          $error_message .= "Invalid web address<br />";
          break; 
       }
    }
    Problem is I need one function that checks to see if text exists within a string...the string can be a filename or in the case above a posted $key
    reference. 'Exists1' function will process the validation code above, however the 'Exists' function will not. In other scripts, like working with filenames 'Exists1' does not work, but 'Exixts' function does. Hope I explained clearly enough.

    Any help is appreciated.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #2
    New Coder
    Join Date
    Mar 2009
    Location
    Texas
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Hello c1lonewolf, I do apologize but I don't exactly understand what you are trying to do, but if you are trying to get the TextExists function to return 1 when the key "my websiteurl is here" to validate they you need to switch the $t and $v in that function as it is below.

    Code:
    function TextExists($v,$t) {
       return ( strstr(strtolower($v), strtolower($t) ) !== false ) ? 1:0;
    }
    If this is not what you meant, I do apologize.
    The Game

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Thanks Mike I'll try that!
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.


  •  

    Posting Permissions

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