Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] Adding a wild card in PHP

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30380
    GreyFox135
    Participant

    Hi Everyone!

    Quick question:

    I want to add a wild card in a script I’m writing. Here’s an example:


    $phone = Phone number;

    if ($phone == "805" . WILDCARD HERE) {
    DO SOMETHING;
    } else {
    DO SOMETHING ELSE;
    }
    ?>

    I’m very new to PHP and tried looking up a wildcard via google, but to no avail.

    Can anyone help me out?

    Thnx!

    #78956
    GreyFox135
    Participant

    Umm, well…

    I want to check if someone’s number starts with 805. Any number after that is irrelevant. It’s the area code I’m interested in. I can’t have it return false.

    Maybe something like this?

    if ($phone == "805" . *)

    this doesn’t work :/

    #78957
    ImpInaBox
    Member

    Try…

      if ((substr($phone, 0, 3) == "805")
    ...

    or look at substr_compare().

    #78965
    GreyFox135
    Participant

    I decided to use string compare:


    $phone = Phone number;

    if (strncmp("805", $phone, 2) == "0") {
    DO SOMETHING
    } else {
    DO SOMETHING ELSE
    }
    ?>

    This worked like a charm

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.