Strange output from echo statement

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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.
$var1 = "test";
echo "This is a " . $var1 . "! This is only a " . $var1;
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
eregi($pattern, $string, $output);//just an example, won't work for
//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?


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- - The #1 Newsgroup Service in the World!
-----==  Over 100,000 Newsgroups - 19 Different Servers! =-----

Re: Strange output from echo statement

ScareCrowe wrote:

Quoted text here. Click to load it

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";

Site Timeline