www.webdeveloper.com
Results 1 to 3 of 3

Thread: dynamic strings

  1. #1
    Join Date
    Sep 2003
    Location
    Netherlands
    Posts
    353

    dynamic strings

    Is it possible to use php to create a string from a name in a file?

    For example.
    In a .txt file are the words: "fish" "cat" and "dog" (and a lot more which are unknown to me)
    I then want to load a page which takes those words and translates them into strings, and then assign values to the new strings.

    So for example "fish" becomes "$fish" and has a value of "55"

    Is this possible? And what would the code be?
    I've tried to make a string using something like the following, but that didn't work.
    PHP Code:
    <?
    $name
    ="wow";
    $begin="$";
    $newvariable=($begin+$name);
    $stringvalue="55";
    $newvariable=$newvariable."=".$stringvalue;
    // gives $newvariable = "$wow=55"
    echo ??????;
    ?>
    How do I turn the contents of $newvariable into the string $wow ?
    Thnx
    <?php function reply_to_thread($user,$problem=NULL) {
    if($user["nice"] === TRUE) { give_possible_solution($problem);}
    else { exec($user,'code_fail',undefined); }
    return TRUE; } ?>

  2. #2
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107
    Code:
    $name="wow";
    $value=55;
    
    $evalstring="$".$name."=".$value.";";
    
    eval($evalstring);
    
    print $wow;
    Bittersweet web development.

  3. #3
    Join Date
    Sep 2003
    Location
    Netherlands
    Posts
    353
    /me feels stupid.
    Why didn't I think of eval()
    Thank you
    <?php function reply_to_thread($user,$problem=NULL) {
    if($user["nice"] === TRUE) { give_possible_solution($problem);}
    else { exec($user,'code_fail',undefined); }
    return TRUE; } ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles