php - Can't get quotes right -


and saw on title. can't quotes right php. want export variables file, can't quoted right, can me?

this code:

    if($sliderconfig = fopen("./slidersettings.class.php", "w")) {         $error[] = 'er 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 succesvol bijgwerkt!'; 

this ouput:

<?php     $slider_text = test;     $text_link = test;     $slider_speed = test;     $text_size = test;     ?> 

and should ouput:

<?php     $slider_text = 'test';     $text_link = 'test';     $slider_speed = 'test';     $text_size = 'test';     ?> 

anyone nows how fix this, if , answer down here. in advance.

you should escape single quotes in string using backslash \ before single quote so:

$configuration = '<?php     $slider_text = \''.$slider_text.'\';     $text_link = \''.$text_link.'\';     $slider_speed = \''.$slider_speed.'\';     $text_size = \''.$text_size.'\';     ?>'; 

alternatively can use double quotes in string , single quotes encase string:

$configuration = '<?php     $slider_text = "'.$slider_text.'";     $text_link = "'.$text_link.'";     $slider_speed = "'.$slider_speed.'";     $text_size = "'.$text_size.'";     ?>'; 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -