嗨,我想知道我可以如何使一个变量等于自己。 所以如果我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