Strange output from echo statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ScareCrowe

    Strange output from echo statement

    Whenever I try to print a string and a variable together I get incorrect
    output. After echoing the variable the rest of the line is ignored.
    //eg.
    $var1 = "test";
    echo "This is a " . $var1 . "! This is only a " . $var1;
    //returns:
    This is a test
    //instead of
    This is a test! This is only a test.

    //At first I corrected the problem by bypassing it like so:
    $var1 = "test";
    echo "This is a " . $var1;
    echo "! This is only a " . $var1;
    //thought it was just a weird nuance, but the fact that it's doing similar
    things with my pattern matches, it has to be something else.

    //Pattern matching:
    $pattern = '<tr><td>(.*)</td></tr>';
    $string = '<tr><td>Test Status</td></tr><tr><td class=\"classy\ ">Test
    Date</td></tr>';
    eregi($pattern, $string, $output);//just an example, won't work for
    cutnpaste
    //running thru eregi returns
    <tr><td>Test Status</td></tr><tr><td class=\"classy\ ">Test Date</td></tr>
    //AND everything else following the (*) in $pattern!
    //instead of
    Test Status


    I'm really at a loss as to why this is like this!
    Any ideas?

    --ScareCrowe




    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
  • 2metre

    #2
    Re: Strange output from echo statement

    ScareCrowe wrote:
    [color=blue]
    > Whenever I try to print a string and a variable together I get incorrect
    > output. After echoing the variable the rest of the line is ignored.
    > //eg.
    > $var1 = "test";
    > echo "This is a " . $var1 . "! This is only a " . $var1;
    > //returns:
    > This is a test
    > //instead of
    > This is a test! This is only a test.
    >[/color]

    What version of PHP are you using?

    I cut and pasted your code into a page (on a server running v4.3.4) and
    it returned the full string as it should.

    BTW if you are keeping the variables outside the strings, use single
    quotes instead of double quotes - this will prevent PHP from having to
    parse the contents of the string. Alternatively you could have written:

    echo "This is a $var1! This is only a $var1";

    Comment

    Working...