无法获得正确的报价

Can't get quotes right

还有你在标题上看到的。我无法用 php 获得正确的引号。我想将一些变量导出到另一个文件,但我无法正确引用它,有人可以帮助我吗?

这是我的代码:

    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';
    ?>

现在知道如何解决此问题的任何人,如果是,请在此处回答。提前致谢。

您应该在单引号前使用反斜杠 \ 转义字符串中的单引号,如下所示:

$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.'";
    ?>';

尝试:

$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"; 

这是你的:

    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!';