Why would I be getting Parse error: syntax error, unexpected T_VARIABLE
on this line?
$fieldLabel = '<label for=".'$fieldNameStripped'.">.'$fieldName'.</label>';
Because you're not using PHP properly - syntax errors:
$fieldLabel = '<label for="' . $fieldNameStripped . '">' . $fieldName . '</label>';
^^^^ ^^^
You had the concatenation operators INSIDE the strings, so you weren't concatenating at all.
Try
$fieldlabel = <<<EOL
<label for="$fieldNameStripped">$fieldName</label>
EOL;
HEREDOCs make such things trivial, and far far easier to read. With a modern syntax highlighting editor, the variables will even stand out for you.
You could also prepare your string like this: $fieldLabel = "{$field->name}";
Here the double quotes surround the outer string mean that PHP will parse variables inside it. You however then have to escape double quotes. I've changed the $fieldName variable to show how you would wrap the variable in {} brackets for items such as object properties (I tend to use them even for regular variables inside strings just because I feel it's better practice to be consistant).
$fieldLabel = '<label for="'.$fieldNameStripped.'">'.$fieldName.'</label>';
Is how you should do it.
In what you have done, there are two problems:
When using .
for concatenation, you should confirm that the strings to both sides of .
should be "properly closed"
.
Also, say if you have $var = 1;
and you echo '$var';
you don't get 1
. you get $var
as output.
your line should be like this
$fieldLabel = '<label for="' . $fieldNameStripped . '">' . $fieldName . '</label>';