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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing contents of a variable to what matches in a language.php file

    I'm curious as to how I go about solving this problem. I get input from the user and store it in a variable. I want the contents of that variable to be replaced by the text in the language file.

    Example:

    User types in "GOOG" stores it in a variable $ticker and then contents of the variable are replaced by the text found in language.php:

    Code:
    'GOOG' => "Google",

    How do I go about doing this? Then assuming the variable's contents can be replaced, would I just echo $ticker and it would display Google?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Is this language.php file something you wrote? What's in it? How would we know anything about it?

  • #3
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    Is this language.php file something you wrote? What's in it? How would we know anything about it?
    Yes, I wrote it and I gave an example of what would be in it, among other tickers. I want the instances of GOOG to be replaced with Google if they entered that or Apple if they entered AAPL. Would I be better off defining a constant and taking the data from the variable to fill it? Even then, how would I go about changing the input?

  • #4
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any ideas?

  • #5
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    This should give you an idea were to start.

    PHP Code:
    <?php
      $post_result 
    $_POST['ticker_symbol'];
      
    $ticker_symbol strtoupper($post_result); // output uppercase

      
    switch ($ticker_symbol) {

      case 
    'GOOG':
      
    $ticker "Google";
      break;

      case 
    'AAPL':
      
    $ticker "Apple";
      break;

      case 
    'QQQQ':
      
    $ticker "PowerShares QQQ";
      break;

      case 
    'USD':
      
    $ticker "US Dollar";
      break;

      default:
      
    $ticker "Sorry invalid input";
      break;

      }

      echo 
    "$ticker";
    ?>

    <form method="post" action="<?php echo $PHP_SELF;?>">
    <input type="text" size="6" maxlength="6" name="ticker_symbol">
    <input type="submit" value="Enter Ticker Symbol" name="submit">
    </form>

    ---
    Leonard Whistler

  • #6
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    define("GOOG","Google");



    echo 
    GOOG
    Let me know if this helps
    Last edited by damon.whitt; 05-04-2009 at 05:58 AM.


  •  

    Posting Permissions

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