Re: newbie question on escaping strings



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>
.



Relevant Pages

  • newbie question on escaping strings
    ... the string escaping is screwing me up. ... - a single or double quote, escaped or otherwise, to demarcate the ... array components. ...
    (php.general)
  • Re: Object Hash vs. object Array preference
    ... > languages. ... JavaScript/JScript Object accepts CDATA literals as property name. ... Array index is unsigned 32 bit value which allows you to hold ... sorry but I used to quote in the way one can see who am I ...
    (comp.lang.javascript)
  • RE: Recording a Macro
    ... I don't thin you need a double quote between a charrage return ) and ... If the double quotes are needed to prevent a syntax error use ... ), Array(_ ... .RefreshStyle = xlInsertDeleteCells ...
    (microsoft.public.excel.programming)
  • Re: Passing an array of chars to a function
    ... newalready returns a pointer. ... cast an array into a pointer, but if you don't it will be done ... You must have a bad short-term memory. ... I did quote it. ...
    (comp.lang.cpp)
  • Re: Variable variable name
    ... numbers first) in a shell script: ... I get the following error message: ... of $file in an array names AD_10K? ... quote the command to prevent filename expansion on the first ...
    (comp.unix.shell)