1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

preg Searh and replace problem

Discussion in 'PHP' started by dcsimmons, Jul 2, 2007.

  1. #1
    I have a record set called rsOrders with a table called shipcountry_ord with the countries in it when using a check out procedure.

    I am trying to set a condition for free shipping, but want to only offer in the US, so I am trying to do a search for "US" in the shipcountry_ord table.

    When selecting "United States" from a dropdown list in the checkout procedure, "US" is placed into the shipcountry_ord table.

    I am trying to use the following code to search for the "US" in the shipcountry_ord table.

    preg_replace("/[^\d]/", "", $row_rsOrder['shipcountry_ord'])=='/US/'

    It isn't working, and I do not know what I am doing wrong.
    dcsimmons, Jul 2, 2007 IP
  2. UnrealEd

    UnrealEd Peon

    Likes Received:
    Best Answers:
    Trophy Points:
    your pattern matches all characters except numbers. You then replace all found characters with nothing (remove them), and attempt to match numbers against a "US".
    I think what you need is this:
    if ( $row_rsOrder['shipcountry_ord'] == 'US' ) {
      // it is a US order
    you don't need regex, unless you store some other (additional) values in the shipcountry_ord field
    UnrealEd, Jul 2, 2007 IP
  3. ansi

    ansi Well-Known Member

    Likes Received:
    Best Answers:
    Trophy Points:
    and incase that there is other information within $row_rsOrder['shipcountry_ord'] as well

    if ( preg_match("/us/i",$row_rsOrder['shipcountry_ord']) )
       // go
    ansi, Jul 2, 2007 IP