#1
  1. No Profile Picture
    silfreed
    Guest
    Devshed Newbie (0 - 499 posts)
    I was previously using eval() to parse a string that contained variables ($var), but when I do this, it also parses dollar signs ($20.31). So, I have envisioned putting brackets around variables (since that is rarely done), and only parse variables w/ brackets around them.

    I can isolate the variables right now, and strip out the brackets [ ], but I can't parse the variable. Here's the code so far:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    $str = 'Text goes [$value]. Insert [$value2] here.';
    $value = 'here';
    $value2 = 'spiffiness';
    echo '$str = '. $str .'<br><br>';
    parse_it($str);

    function parse_it($str) {
    $offset = 0;
    $start = strpos($str, '[$', $offset);
    $end = strpos($str, ']', $offset);
    while($start != -1) {
    $front = substr($str, 0, $start);
    $middle = substr($str, $start+1, $end-$start-1);
    $back = substr($str, $end+1);

    eval ("echo "$middle";");

    echo '$start = '. $start .'<br>';
    echo '$end = '. $end .'<br>';
    echo '$front = '. $front .'<br>';
    echo '$middle = '. $middle .'<br>';
    echo '$back = '. $back .'<br>';

    $str = $front . $middle . $back;
    echo '$str = '. $str .'<br><br>';

    $offset = $end + 1;
    $start = strpos($str, '[$', $offset);
    $end = strpos($str, ']', $offset);
    if($start === false) {
    $start = -1;
    }
    }
    }

    ?>
    [/code]
    Thanks for any help you can provide.

    [This message has been edited by silfreed (edited July 25, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    Call the parse_it() function after you declare/write it. PHP reads the code from top to bottom, and it doesn't know what to do with a function that's used ahead of it's declaration.

    ------------------
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson

Similar Threads

  1. array explode ( string separator, string string [, int limit])
    By beemee_freeserv in forum HTML Programming
    Replies: 4
    Last Post: February 5th, 2004, 10:56 AM
  2. mgetty+sendfax on RH9
    By ayrin in forum Linux Help
    Replies: 0
    Last Post: January 31st, 2004, 02:11 AM
  3. SDL_ttf string parsing
    By aerea in forum C Programming
    Replies: 0
    Last Post: January 12th, 2004, 07:22 PM
  4. Parsing and formating a string through XSL
    By relativity in forum XML Programming
    Replies: 3
    Last Post: January 8th, 2004, 06:35 AM
  5. Replies: 4
    Last Post: January 6th, 2004, 03:19 AM

IMN logo majestic logo threadwatch logo seochat tools logo