Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm function that change double quotes to single quotes in string

Tags:

php

ide

phpstorm

I'm looking for a function in PhpStorm that transform the string like:

echo "my string: $var1, $var2, $var3";

into something like that:

echo 'my string: '.$var1.', '.$var2.', '.$var3';

Thanks in advance

like image 344
PoliAkustyczny Avatar asked Dec 28 '15 11:12

PoliAkustyczny


People also ask

How do you replace a double quote in a string?

If you want to add double quotes(") to String, then you can use String's replace() method to replace double quote(") with double quote preceded by backslash(\").

Can we use single quotes in place of double quotes to declare a string variable?

Both single (' ') and double (" ") quotes are used to represent a string in Javascript. Choosing a quoting style is up to you and there is no special semantics for one style over the other. Nevertheless, it is important to note that there is no type for a single character in javascript, everything is always a string!

Does SED work with double quotes?

@DummyHead Here's another approach: if you use single quotes, the sed command is exactly as you type it. If you use double quotes, you must take into account all shell substitutions and elaborations to "visualize" what command is eventually passed on to sed.

How do you replace single quotes with double quotes?

Use the String. replace() method to replace double with single quotes, e.g. const replaced = str. replace(/"/g, "'"); . The replace method will return a new string where all occurrences of double quotes are replaced with single quotes.


3 Answers

  1. Install "PHP 1Up!" plugin and restart IDE.

  2. Now you will have new intention available (accessible via Alt + Enter or via light bulb icon):

    enter image description here


As others have already mentioned:

  • no noticeable speed gains
  • for possibly better readability, surround variables with {}, e.g. echo "my string: {$var1}, {$var2}, {$var3}";
like image 164
LazyOne Avatar answered Oct 25 '22 11:10

LazyOne


First we have to do a little phpstorm setup.

Settings > Editor > General > Smart Keys Please mark this. "Surround selection on typing quote or brace"

Click OK.

Then select the entire code with double quotes. Now press the single quotation key.

Done.

like image 35
Emrah Tuncel Avatar answered Oct 25 '22 10:10

Emrah Tuncel


No way. You can explode it in concatenation by hands and then convert quotes:

  1. With internal 'Replace quotes' action
  2. Regexp find/replace
  3. String manipulation plugin
like image 33
Ostin Avatar answered Oct 25 '22 10:10

Ostin