这是我的代码:
if($sliderconfig = fopen("./slidersettings.class.php", "w")) {
$error[] = 'Er was een probleem met het veranderen van de slider_config, contacteer site-admin.';
}
$configuration = '<?php
$slider_text = '.$slider_text.';
$text_link = '.$text_link.';
$slider_speed = '.$slider_speed.';
$text_size = '.$text_size.';
?>';
fwrite($sliderconfig, $configuration);
fclose($sliderconfig);
$message[] = 'De configuratie is succesvol bijgwerkt!';
这是输出:
<?php
$slider_text = test;
$text_link = test;
$slider_speed = test;
$text_size = test;
?>
这应该是输出:
<?php
$slider_text = 'test';
$text_link = 'test';
$slider_speed = 'test';
$text_size = 'test';
?>
任何人都知道如何解决这个问题,如果有的话,你可以在这里解答。提前谢谢。
答案 0 :(得分:1)
你应该在单引号之前使用反斜杠\
来转义字符串中的单引号,如下所示:
$configuration = '<?php
$slider_text = \''.$slider_text.'\';
$text_link = \''.$text_link.'\';
$slider_speed = \''.$slider_speed.'\';
$text_size = \''.$text_size.'\';
?>';
或者,您可以在字符串和单引号中使用双引号来包含字符串:
$configuration = '<?php
$slider_text = "'.$slider_text.'";
$text_link = "'.$text_link.'";
$slider_speed = "'.$slider_speed.'";
$text_size = "'.$text_size.'";
?>';
答案 1 :(得分:1)
尝试:
$configuration = '
$slider_text = "'.$slider_text.'";
$text_link = "'.$text_link.'";
$slider_speed = "'.$slider_speed.'";
$text_size = "'.$text_size.'";
';
echo $configuration;
输出:
$slider_text = "aaa";
$text_link = "aaa";
$slider_speed = "aaa";
$text_size = "aaa";
答案 2 :(得分:0)
这是你的:
if($sliderconfig = fopen("./slidersettings.class.php", "w")) {
$error[] = 'Er was een probleem met het veranderen van de slider_config, contacteer site-admin.';
}
$configuration = '<?php
$slider_text = '.$slider_text.';
$text_link = '.$text_link.';
$slider_speed = '.$slider_speed.';
$text_size = '.$text_size.';
?>';
fwrite($sliderconfig, $configuration);
fclose($sliderconfig);
$message[] = 'De configuratie is succesvol bijgwerkt!';
这应该是这样的:
if($sliderconfig = fopen("./slidersettings.class.php", "w")) {
$error[] = 'Er was een probleem met het veranderen van de slider_config, contacteer site-admin.';
}
$configuration = '<?php
$slider_text = "'.$slider_text.'";
$text_link = "'.$text_link.'";
$slider_speed = "'.$slider_speed.'";
$text_size = "'.$text_size.'";
?>';
fwrite($sliderconfig, $configuration);
fclose($sliderconfig);
$message[] = 'De configuratie is succesvol bijgwerkt!';