-2

I've been trying to find solution somewhere for this possibly simple fix but, I haven't been able to surprisingly.

How is it possible to stop PHP from assuming a variable is a part of a string. E.g.

The line of code is $string = "slfnnwnfkw49828323$dgjkt^7ktlskegjejke"; how do you stop PHP from thinking '$dgjkt' is a variable within the string when it's really a part of the full string as characters. Thanks

KmanOfficial
  • 77
  • 1
  • 7
  • 4
    Possible duplicate of [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – faintsignal Jan 07 '18 at 20:57
  • Possible duplicate of [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) –  Jan 07 '18 at 20:58
  • 1
    No need to down-vote: just vote as an appropriate duplicate and move on.. – user2864740 Jan 07 '18 at 21:01

3 Answers3

2

Use this string like $sting = 'slfnnwnfkw49828323$dgjkt^7ktlskegjejke'

Adittya Verma
  • 270
  • 1
  • 11
  • Hope this link will explain this https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – Adittya Verma Jan 07 '18 at 21:00
  • 1
    you're answering the question, so answer it. –  Jan 07 '18 at 21:17
  • 1
    Single quoted strings are the easiest way to specify string. This method in used when we want to the string to be exactly as it is written. When string is specified in single quotes PHP will not evaluate it or interpret escape characters except single quote with backslash (‘) and backslash(\) which has to be escaped. In double quoted strings other escape sequences are interpreted as well any variable will be replaced by their value. – Adittya Verma Jan 07 '18 at 21:21
  • @AdittyaVerma Please give credit when using others' material. http://programming-tips.in/php-what-is-the-difference-between-single-quoted-and-double-quoted-strings/ – faintsignal Jan 08 '18 at 04:04
  • I didn't refer any material which you mentioned above. – Adittya Verma Jan 08 '18 at 06:29
0

You have to use ' instead of " otherwise php tries to find any variables inside your string

DZDomi
  • 1,685
  • 15
  • 13
0

Read the manual.

The most important feature of double-quoted strings is the fact that variable names will be expanded. See string parsing for details:

When a string is specified in double quotes or with heredoc, variables are parsed within it.

There are two types of syntax: a simple one and a complex one. The simple syntax is the most common and convenient. It provides a way to embed a variable, an array value, or an object property in a string with a minimum of effort.

The complex syntax can be recognised by the curly braces surrounding the expression.

shukshin.ivan
  • 11,075
  • 4
  • 53
  • 69