What a Newb! Simple $lowercase = strtolower (wtf?)

Discussion in 'PHP' started by MaxBush, May 3, 2012.

  1. #1
    I'm new to this. I created a form to do a search and replace output.

    This works:
    <?php echo str_replace(' ',' ','-', $_POST["city2"]); ?>

    What I get: Moses-Lake


    But when I try to force lower case, I can't figure out the proper format:

    <?php echo str_replace(' ','-', $_POST["city2"]), $lowercase = strtolower($_POST["city2"]); ?>

    What I want: moses-lake


    Thank you so much for any help on this, I think I'm close
     
    MaxBush, May 3, 2012 IP
  2. downloadphpscripts

    downloadphpscripts Peon

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #2
    Hi Max,

    You'll want to change this:

    to this:

    
    <?php echo str_replace(' ','-', strtolower($_POST["city2"])); ?>
    
    PHP:
     
    downloadphpscripts, May 3, 2012 IP
  3. MaxBush

    MaxBush Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Like a charm! Thank you.

    Do you have a website? Download PHP Scripts?

    If so, pm me.

    Also, I read your profile. PM me your rates for programming and your contact info. Do you work with wordpress often?

    ----------------

    I have one more issue, then my form is complete. I was able to figure most of it out, just these two stumped me.

    My last issue with this form:

    User enters a State abbreviation: CA

    In one section I have:

    <?php echo $_POST["state"]; ?>

    Which, of course, gives me 'CA'

    In another section I am trying to have:

    california (spelled out in lowercase)

    If you could just point me in the right direction and give me an example and I should be able to piece all the states together.

    Thanks again so much for the help!
     
    MaxBush, May 3, 2012 IP
  4. downloadphpscripts

    downloadphpscripts Peon

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #4
    Hi again Max,

    I've run into that same issue with the states before. What i did was make an include file that contains an array with the state abbreviations as the keys and the full state name as the value. That way, when you needed to spell it out you could echo it out by key. For example:

    state_config.php would contain

    $state_array['CA'] = "California";
    $state_array['CO'] = "Colorado";
    // rest of states here

    Then when you needed the full name:

    <?php
    echo $state_array[$_GET["state_abbr"]]; // will echo full name

    //or if you need the strtolower

    echo strtolower($state_array[$_GET["state_abbr"]]);
    ?>

    I'm sending a PM now.
     
    downloadphpscripts, May 3, 2012 IP
  5. MaxBush

    MaxBush Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Shesh, don't know what I'm missing:


    index.html file:

    <html>
    <body>

    <form action="welcome.php" method="post">
    State: <input type="text" name="state_abbr" />
    <BR /><BR />
    <input type="submit" />
    </form>

    </body>
    </html>

    ---------------------------

    welcome.php file:

    <?php include("state_config.php"); ?>

    Abbreviated: <?php echo $_POST["state_abbr"]; ?><br /><br />
    Lower Case, spelled out: <?php echo strtolower($state_array[$_GET["state_abbr"]]); ?>


    ---------------------------


    state_config.php file:

    <?php

    $state_array['CA'] = "California";
    $state_array['CO'] = "Colorado";

    ?>
     
    MaxBush, May 3, 2012 IP
  6. downloadphpscripts

    downloadphpscripts Peon

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #6
    Hi Max,

    It's this line right here (it's looking for $_GET instead of $_POST):

    Lower Case, spelled out: <?php echo strtolower($state_array[$_GET["state_abbr"]]); ?>

    Should be:

    Lower Case, spelled out: <?php echo strtolower($state_array[$_POST["state_abbr"]]); ?>
     
    downloadphpscripts, May 3, 2012 IP