S
S
sorry_i_noob2018-02-15 16:01:45
phpstorm
sorry_i_noob, 2018-02-15 16:01:45

PhpStorm how to prevent adding slashes when inserting code into a string?

Hello. I have such a problem. If I take this code:

<div class="board-article__tags-bar tags-bar">
      <div class="tags-wrap">
        <?php
        foreach ($item_tags as $tag) {
          echo '<a href="/' . $material_alias . '?tag=' . $tag->name . '" class="tag label label-success">' . $tag->name . '</a>';
        }
        ?>
      </div>
    </div>

and insert it between the quotes of this code: Then the IDE will add slashes. This is what the code will turn into (note the line with echo):
$result = ''
$result = '<div class="board-article__tags-bar tags-bar">
      <div class="tags-wrap">
        <?php
        foreach ($item_tags as $tag) {
          echo \'<a href="/\' . $material_alias . \'?tag=\' . $tag->name . \'" class="tag label label-success">\' . $tag->name . \'</a>\';
        }
        ?>
      </div>
    </div>';

Tell me, please, how to make sure that PhpStorm does not change anything in the code when inserting code into a string (between quotes)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
neol, 2018-02-15
@sorry_i_noob

ctrl+alt+shift+v or Edit -> Paste simple
Can be reassigned in Past Simple settings to ctrl + v.

O
OKyJIucT, 2018-02-15
@OKyJIucT

It is he who escapes quotes so that the syntax does not break and everything works for you. If they are removed, then the first unescaped quote will end the line, and there will be a syntax error further.
Even the Toaster editor highlights double quotes correctly, and look what happens after the first unescaped one:

$result = '<div class="board-article__tags-bar tags-bar">
      <div class="tags-wrap">
        <?php
        foreach ($item_tags as $tag) {
          echo '<a href="/' . $material_alias . '?tag=' . $tag->name . '" class="tag label label-success">' . $tag->name . '</a>';
        }
        ?>
      </div>
    </div>';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question