I would like to set a variable equal to a string and a variable. The variable is a string as well coming through AJAX. I know $data3
is coming through because when I change file_put_contents('TestFile.json', $updated);
to file_put_contents('TestFile.json', $data3);
it works. So there's no problem with the AJAX.
I know this is not proper JSON at all, I'm just testing. The value of $data3
is the string "string". So what I want the outcome to be is "Testing string".
BELOW IS THE CURRENT CODE: <?php $data3 = $_REQUEST ["data3"]; $updated = 'Testing ' + $data3; file_put_contents('TestFile.json', $updated); ?>
You are trying to add two strings together with a JAVA style operation (+). In PHP you use . to concatenate.
$data3 = $_REQUEST['data3'];
$updated = 'Testing ' . $data3;
file_put_contents('TestFile.json', $updated);