Re: newbie question on escaping strings



On Nov 29, 9:36 am, ZeldorBlat <zeldorb...@xxxxxxxxx> wrote:
On Nov 29, 11:01 am,howardk<howar...@xxxxxxxxx> wrote:



I know this isn't a hard one, but it's making me slightly crazy. :-) I
have the following code that works just fine:

while( $row = mysql_fetch_array( $result ) ){
$id = $row['practcatid'];
$name = $row['practcatname'];
print "<option value='$id'> $name </option>\n";

}

What I'd like to be able to do however is use the two array
components, $row['practcatid'] and $row['practcatname'], in the final
print statement directly rather than dereferencing them to $row and
$name first. However, the string escaping is screwing me up. I need:

1 - a single or double quote to demarcate the entire string
2 - a single or double quote, escaped or otherwise, to demarcate the
ends of the attribute value, and
3 - a single quote (I think!), escaped or otherwise, to name the $row
array components.

Whatever it takes, I can't get it to work. Help!

TIA,
Howard

You want something like this:

print "<option value='{$row['practcatid']}'> {$row['practcatname']} </
option>\n";

Read this for more information:

<http://www.php.net/manual/en/
language.types.string.php#language.types.string.parsing.complex>

Thanks for the pointer! That's a big help.
Howard
.