Results 1 to 6 of 6

Thread: Can you use wildcards in php?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default Can you use wildcards in php?

    In Rbase there was a command you could use to see if a text field contained a specified string. For example:

    Code:
    SELECT * FROM addresslist WHERE address2 CONTAINS "CA";
    Is there a command like that in php? I know you can say in phpMyAdmin:

    Code:
    SELECT * FROM addresslist WHERE address2 LIKE "%CA%";
    but I get the feeling you can't use wildcards in straight php. Can you?

    Thanks.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You can use wildcard characters in SQL statement in PHP or rather in any language. From PHP's point of view it is just a string nothing else. But this string will be get executed within a database and against a table and at that point this string will be considered as a valid SQL statement. In a valid SQL statement you can use wildcard characters.

  3. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    So this is a valid statement?

    Code:
    $sql = 'SELECT * FROM addresslist WHERE address2 LIKE "%CA%" ';
    Last edited by kuau; 07-30-2008 at 06:43 AM. Reason: added tags

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Yes the SQL statements are valid.

  5. #5
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Yes, but in the second question, are the underscores wildcards? And if not, how could this query ever find any data to match the where clause? But it does, which makes no sense to me. That is the question.

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I am extremely sorry Kuau in MySQL underscore character is wildcard character for representing a single character.
    Code:
    
    $day = "_y_____";
    If you consider the above one it will check all the value whose second character is 'y' and the total length of the value is 7.

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
  •