Amin Hijaz Amin Hijaz - 5 months ago 15
PHP Question

How to use put var between double quotes

I want to use this code

$person = ""$steamid" "" "abcdefghijklmnopqrstu" "ce"\n";


for example if
$steamid
= STEAM_0:0:123456

the outpur should look like this

"STEAM_0:0:123456" "" "abcdefghijklmnopqrstu" "ce"

I hope someone can correct my PHP code

$person = ""$steamid" "" "abcdefghijklmnopqrstu" "ce"\n";

Answer

Use . (dot) between variables to join them.

Example:

$var = $somevar . "sometext" . $anothervar . "and it works" . "you can add more text";

Spaces doesn't matter between variables and quoted text.

Explanation:

There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side.

<?php
    $a = "Hello ";
    $b = $a . "World!"; // now $b contains "Hello World!"

    $a = "Hello ";
    $a .= "World!";     // now $a contains "Hello World!"
?>

Here is detailed explanation of same thing from php manual

And to answer your question, since you need to output these -> " " , you need to use single quotation marks in code. So, your code would look like this:

<?php

    $steam = '"STEAM_0:0:123456"'; 
    echo $person = $steam . ' ""' .' "abcdefghijklmnopqrstu" "ce"';

?>

Here are screenshots:

Code

and

output

Comments