This looks like an HTML being generated by Javascript. So it’s a little different than what you ask for. To make PHP write this, you have to choose which type of delimiter to use in PHP and then set the delimiter that will be escaped.
Example, keeping the original shape:
<options += '<option value="' + j[i].CodCidade + '">' + j[i].NomeCidade + '</option>';
To put this into a PHP variable would look like this:
$foo = "<options += '<option value=\"' + j[i].CodCidade + '\">' + j[i].NomeCidade + '</option>';";
Here we use double quote as delimiter, so all double string tiles must be backslashed
Another way, using heredoc
$foo = <<<HTML
<options += '<option value="' + j[i].CodCidade + '">' + j[i].NomeCidade + '</option>';
HTML;
The advantage is that you don’t need to escape anything except in very specific cases. So just play everything in the original form.
Take care with the closing. In the example above, HTML;
cannot contain spaces or tab at the beginning.
This is much cleaner and practical to handle templates because you don’t have to make escapes. It is very convenient to assign extensive codes where give much work to make all escapes.
Let’s complicate it with an example of output buffering
<?php
ob_start();
?>
<options += '<option value="' + j[i].CodCidade + '">' + j[i].NomeCidade + '</option>';
<?
echo ob_get_clean();
Output control is used for specific cases. Obviously it is not used for simple and ordinary cases where we can solve with concatenation or heredoc. An example of using output buffering is building templates.
*terms used:
double quote -> aspa dupla
backslash -> barra invertida
Dude, you completely changed the question. Better make a new one, otherwise you invalidate the answers below completely.
– user28595
Thanks for the tip
– joari de souza santos