Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concatenate a backslash between two variables?

I want to concatenate a backslash between two variables when passing them in the arguments of a function so they form a filepath.

turbo_function($variable1.\.$variable2, $otherargument);

I'm sure the backslash needs to be escaped. I've tried wrapping it in quotes and double quotes.

How can I concatenate the backslash to the variables successfully?

like image 530
blarg Avatar asked Dec 12 '13 10:12

blarg


People also ask

How do you Deconcatenate two strings?

You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.

Can you concatenate variables?

In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect.

What is the operator of concatenation?

The concatenation operator is a binary operator, whose syntax is shown in the general diagram for an SQL Expression. You can use the concatenation operator ( || ) to concatenate two expressions that evaluate to character data types or to numeric data types.

What is the syntax to concatenate two string variables?

Syntax: string new_string = string init + string add; This is the most easiest method for concatenation of two string. The + operator simply adds the two string and returns a concatenated string.


2 Answers

Escape the backslash with a backslash !

Like this..

turbo_function($variable1."\\".$variable2, $otherargument);
like image 134
Shankar Narayana Damodaran Avatar answered Oct 21 '22 05:10

Shankar Narayana Damodaran


  1. It needs to be a string
  2. It is an escape character, so inside a string it must be escaped

Such:

$variable1 . "\\" . $variable2
like image 37
Quentin Avatar answered Oct 21 '22 05:10

Quentin