473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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! =-----
Jul 17 '05 #1
1 1494
ScareCrowe wrote:
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.


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";
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Margaret MacDonald | last post by:
Running on a single-cp machine under W2K, this test program <?php function show_array ( $s, $a ) { echo '<table cellspacing="2" cellpadding="2 border="1" > <tr><td>======&nbsp;' . $s ....
0
by: Ethan | last post by:
I've been having some really weird problems with a very simple PHP app. I'm wondering if anyone can help me sort this out. I have a page that prints out the results of a MySQL query as an HTML...
13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
2
by: peridian | last post by:
I've gotten a really weird result crop up on my site, and I can't find any information on the web that it has been seen elsewhere. Given how weird this is, I guess it's probably a symptom of either...
2
by: ELINTPimp | last post by:
Hello all, Have a really interesting problem (at least to me) with my upload_file() function. I have it working now, with a bit of a work around, but would like to know what everyone thinks in...
2
by: keeps21 | last post by:
Hi I have a script that checks whether a user is logged in or not. If the user are not logged in they are directed to the login page. else the user is logged in. If the user is logged in...
9
by: Dave | last post by:
Hi guys, I have just set up a duplicate server running: apache 2.54, mysql 5.04 and php 5.04 This is the same setup as as the server we are using now, apart from the hardware inside. I have...
1
by: Marcel Molenaar | last post by:
Anyone ever experienced this problem. When i pass a mysql result to the constructor of a class and use that resultset inside that class the original resultset outside the class gets affected...
2
by: KDawg44 | last post by:
Hi, I have the following code: $resultSet = mysql_query($sqlString); $numResults = mysql_num_rows($resultSet); echo "Num Results = " . $numResults . "<br/>"; for ($i = 0; $i < $numResults;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.