So it appears that you have trouble to separate your strings with either " or â (single or double quote) when you have HTML in those strings.
In PHP, you can use both, either double-quote or single-quote to surround a string.
For example, you could do:
$text = "this is a text";
OR
$text = 'this is a text';
Both works. The difference is that with the double-quote, you can use variable inside it and PHP will change the variables for its value. For example:
$myvar = "hello";
$text = "this is some random text: $myvar"
if you echo the variable $text, it will give you
this is some random text: hello
If you try it with single quote, like this:
$myvar = âhelloâ;
$text = âthis is some random text: $myvarâ
Youâll get:
this is some random text: $myvar
PHP didnât try to parse the string and change the variable $myvar because I used single quotes.
Now, you can use the double quotes or single quotes. Single quotes are faster, but you shouldnât notice it until you treat thousands of string. So you can choose whatever you want.
For HTML, itâs the same thing for arguments. You can use double quotes or single quotes. Example:
<form action='index.php'>
is the same as
<form action="index.php">
You canât however, in PHP and HTML, start a string with a double-quote and close it with a single quote. It has to be the same.
So, when you mix HTML and PHP, you should choose one separator for PHP and one for HTML. IMO, using double quotes for PHP and single quote for HTML is easier to read, but itâs just personal thing.
For example:
echo "<form action='index.php'>";
When you need to add variable in this, yes, you can use the point â.â to concatenate strings with variables. However, since using double-quotes with PHP will change the variable inside it, you could write
echo "<select name='$select_name' id='$select_id'>";
instead of
echo "<select name=" . $select_name . " id=" . $select_id . ">";
See how the first piece of code is easier to read than the second?
Or, as @ralphm suggested, you can also use:
echo '<select name="' . $select_name . '" id="' . $select_id . '">';
But, IMO, itâs harder to read, but you choose whatever you want.
Also, please consider not echoing HTML and just outputting it like this:
<select name="<?= $select_name ?>" id="<?= $select_id ?>">
<?php foreach ($items as $key => $value): ?>
<option value='<?= $key ?>'><?= $value ?></option>
<?php endforeach; ?>
</select>
IMO, this is even more easier to read.
I also wrote a post about dealing with quotations with PHP if youâre interested to know more. If you read it, donât hesitate to tell me your opinion 