Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple question

Status
Not open for further replies.
Use
Code:
echo '<tr><td valign=top class=HeaderRow1><b>Name:&nbsp;<font color=black>
<input type=TEXT name=name value="' .$name. '"  size=20  maxlength=20>';
The value needs to be enclosed in quotes for it to display a value with spaces. If you do a show souces, you will see what it looks like before and after putting quotes around it.

Ken
 
Because you're not putting doublequotes around your attribute values.

The HTML tag should, when output, read:

<input type="TEXT" name="name" value="Paul hanson" size="20" maxlength="20">


for single-word attribute values, it doesn't matter. But for multiword attribute values, your browser uses whitespace to tell where one attribute value ends and the next one begins. So the browser interprets your HTML as:

<input type="TEXT" name="name" value="Paul" hanson size="20" maxlength="20">

thinking that hanson is an attribute, not part of an attribute value

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I'm still learning php too, but I will try to summarise the . character. It is effectively a concatenation of variables.

For example in the code below, the last variable (string) is cat'd to $name which is cat'd to the first variable (string) which is then printed.

Code:
print  "Hi ".$name.", welcom to php";
 
There are multiple ways to include the value of a variable in a string.

One way is to reference the variable inside a double-quoted string:

$bar = "bar";
$a = "foo $bar";


This becomes problematic when the string you are creating itself contains doublequotes. You have to escape the interior doublequotes so that PHP knows they're part of the string and not string delimiters:

$bar = "bar";
$a = "foo \"$bar\"";

To my eye, this is less readable, particularly when you have a lot of interior doublequotes that must be escaped. Like your typical HTML output:

print "<input type=\"text\" name=\"foo\" value=\"$bar\" class=\"nameinput\">";


The workaround I prefer is to limit strings with singlequotes. The problem with this method is that variables are not interpolated inside singlequotes:

$bar = "foo";
print 'foo: "$bar"';

will literally output:

foo: "$bar"

So I break the string into parts and use the "." concatenation operator:

$bar = 'foo';
print 'foo: "' . $bar . '"';

this will output what I expect:

foo: "foo"


My own style of programming in PHP is to use singlequotes to limit strings and thus the concatenation operator. The exception to this rule is when my code is generating SQL queries. Since it is common for SQL queries to have interior singlequotes, I limit string literals with singlequotes -- but I still use the "." operator.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top