1

和你在标题上看到的。我无法使用 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';
    ?>

现在知道如何解决此问题的任何人,如果是这样,您可以在这里回答。提前致谢。

4

3 回答 3

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.'";
    ?>';
于 2016-07-06T10:49:35.500 回答
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"; 
于 2016-07-06T10:51:40.483 回答
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!';
于 2016-07-06T10:54:39.157 回答