嗨,我想知道我可以如何使一個變量等於自己。 所以如果我echo $var
它顯示在我的屏幕上顯示$var
。 我一直在嘗試使用php編寫一個完整的php腳本到一個新文件,但是當我寫入文件時,除了我的變量之外的所有工作都消失了,我懷疑它是因爲它們什麼都沒有,所以我試圖讓它們自己平等。設置一個變量等於自己作爲一個字符串在PHP
$my_file = '../../../'.$_POST['username'].'.php';
$handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
$data = "
<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_database = 'fitnesstest';
$con = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish
a DB connection');
mysql_select_db($db_database,$con);
$date = strtotime('+3 day');
$dates = date('M d, Y', $date);
mysql_query('INSERT INTO ".$_POST['username']."
(`id`, `name`, `push_ups`, `sit_ups`, `burpees`, `pull_ups`, `body_rows`, `overs`,
`tricep_dips`, `run`, `plank_hold`, `squat_hold`, `thrusters`, `hanging_abs`, `row`,
`weight`, `bi`, `tri`, `s_scap`, `s_illiac`, `arm`, `chest_hip`, `waist`,
`belly_delts`, `thigh`)
VALUES
(NULL, '$dates', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0')');
?>
";
file_put_contents($my_file, $data);
fclose($handle);
在$data
每個變量成爲其寫入新文件的空白空間。 請大家幫忙,非常感謝。提前致謝。
用單引號包裹它,而不是雙引號引用 –
我會試一試,但我敢肯定多數民衆贊成它是如何當我第一次嘗試 – camz17
@ user2707380在單引號字符串,PHP變量將不會被評估,因爲它們是雙引號字符串。閱讀[手冊](http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single)。 – crush