Results 1 to 9 of 9
-
08-25-2009, 10:05 PM #1WHT Addict
- Join Date
- Jun 2008
- Posts
- 128
Basic PHP Syntax Question PLEASE HELP!
Hi I'm learning PHP using HeadFirst PHP&MYSQL but now I ran into a slight problem while trying to understand this script.
Code:echo '<input type="checkbox" value="' . $row['id'] . '" name="todelete[]" />';
I know that '.' means concatenate in PHP but I don't know why it's needed in this case.
Thanks.
-
08-25-2009, 10:07 PM #2
I need to read better.
It's needed here so the dynamic part (in bold) can be parsed by PHP.
echo '<input type="checkbox" value="' . $row['id'] . '" name="todelete[]" />';Last edited by bear; 08-25-2009 at 10:12 PM.
Your one stop shop for decentralization
-
08-25-2009, 10:16 PM #3WHT Addict
- Join Date
- Jun 2008
- Posts
- 128
Thanks but I still don't get it. Are dots used as concatenation in this case ? If yes, what is it concatenating with? The two single-quotation marks?
-
08-25-2009, 10:30 PM #4
echo '<input type="checkbox" value="' . $row['id'] . '" name="todelete[]" />';
PHP code within the single quotes won't get parsed, so it's taking the first half of the echo statement and wrapping it within single quotes (because it contains double quotes). It then takes the dynamic part, parses it, and strings it together with the first part and the last part to make one long echo string...with the dynamically generated content in the middle.Your one stop shop for decentralization
-
08-26-2009, 01:46 AM #5WHT Addict
- Join Date
- Jun 2008
- Posts
- 128
OMg thanks now I see the difference. I had thought that the entire echo statement was one part instead of 3 parts. Is there any other way to achieve the same result without using concatenation? Is there any benefit of using concatenation because I don't really like it since it makes things messy...
-
08-26-2009, 02:27 AM #6Newbie
- Join Date
- Mar 2009
- Posts
- 27
There's a few different ways. see: http://php.net/manual/language.types.string
Or use a function like: http://php.net/manual/function.sprintf
-
08-26-2009, 02:41 AM #7Junior Guru Wannabe
- Join Date
- Jun 2009
- Posts
- 35
Try like this:
PHP Code:
echo "<input type=\"checkbox\" value=\"{$row['id']}\" name=\"todelete[]\" />";
-
08-26-2009, 03:49 AM #8WHT Addict
- Join Date
- Jun 2008
- Posts
- 128
Thanks everyone. I guess I will have to get used to these quotation rules.
-
08-26-2009, 08:15 AM #9Web Hosting Master
- Join Date
- May 2009
- Posts
- 766
Or, my personal preference for clean code, use the nowdoc syntax (http://us2.php.net/manual/en/languag....syntax.nowdoc)
PHP Code:echo <<<HTML
<input type="checkbox" value="{$row['id']}" name="todelete" />
HTML;
Similar Threads
-
Very simple php syntax question.Plz help me check.
By Zach185 in forum Programming DiscussionReplies: 9Last Post: 05-01-2006, 11:10 AM -
DNS proper SYntax Question
By neoshell in forum Hosting Security and TechnologyReplies: 3Last Post: 01-12-2004, 09:56 PM -
mysql_query syntax question
By Jeanco in forum Programming DiscussionReplies: 6Last Post: 12-26-2003, 07:31 AM -
stuck on syntax of a basic mysql command
By Derrick in forum Programming DiscussionReplies: 30Last Post: 12-01-2003, 01:42 PM -
mod_rewrite syntax question
By RandallKent in forum Hosting Security and TechnologyReplies: 0Last Post: 04-02-2003, 10:23 PM