0

With this code:

$html .= " 
  <input type='text' name='participant[" . $k . "][answer]' 
   class='form-control'" . ($required ? " required" : ""). ">";

The generated input is like:

<input type='text' 
name='participant[1][answer]' class='form-control' required>

Do you know how to have "" instead of ''? Like:

<input type="text" name="participant[1][answer]" class="form-control" required>

1 Answers1

0

You would need to escape the quotation marks with backslashes:

$html .= " 
<input type=\"text\" name=\"participant[" . $k . "][answer]\" 
class=\"form-control\"" . ($required ? " required" : ""). ">";

However, note that there is absolutely no difference between the two; they'll still be processed the same way.

Note that PHP variables will be evaluated inside double quotes (and not single quotes), so you could even shrink this down to the following equivalent code:

$html .= " 
<input type=\"text\" name=\"participant[$k][answer]\" 
class=\"form-control\"" . ($required ? " required" : ""). ">";
Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
  • 1
    Why not suggest single quotes? Its much cleaner and you don't need to escape anything: https://3v4l.org/UGLEZ – Lawrence Cherone Aug 13 '18 at 00:24
  • ... or [HEREDOC](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) – Phil Aug 13 '18 at 01:09