gamesmad Posted July 11, 2006 Share Posted July 11, 2006 I get the error -[code]Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /home/gamesm/public_html/freeforums/suspend.php on line 26[/code]Lines 21 - 26 go like this -[code]21 $settingscontent = file_get_contents($settingsdir);2223 $mode[0] = "$maintenance = 0;";24 $newmode[0] = "$maintenance = 2;";2526 $newsettingscontent = preg_replace($mode, $newmode, $settingscontent);[/code]Any idea where I am going wrong?? Its stopping my script from working...Will Quote Link to comment https://forums.phpfreaks.com/topic/14313-i-get-php-warning-then-my-script-doesnt-work/ Share on other sites More sharing options...
nogray Posted July 11, 2006 Share Posted July 11, 2006 I think you need a \ before the $ in your mode strings[code]23 $mode[0] = "\$maintenance = 0;";24 $newmode[0] = "\$maintenance = 2;";[/code]If you want to change the actual text "$maintenance" not the variable value of $maintenanceAlso, since you are not using any reg expressions, it's best to use str_replace() because it runs faster and uses less resources. Quote Link to comment https://forums.phpfreaks.com/topic/14313-i-get-php-warning-then-my-script-doesnt-work/#findComment-56379 Share on other sites More sharing options...
gamesmad Posted July 11, 2006 Author Share Posted July 11, 2006 OK, I had a go with str_replace, now there is no error, but it doesnt work. I have attached the file.Will[attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/14313-i-get-php-warning-then-my-script-doesnt-work/#findComment-56402 Share on other sites More sharing options...
nogray Posted July 11, 2006 Share Posted July 11, 2006 you need to add a \ infront of the $ in your strings, otherwise the script will look for the $maintenance value[code]$newsettingscontent = str_replace("\$maintenance = 0;", "\$maintenance = 2;", "$settingscontent");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14313-i-get-php-warning-then-my-script-doesnt-work/#findComment-56429 Share on other sites More sharing options...
gamesmad Posted July 11, 2006 Author Share Posted July 11, 2006 Now the file doesnt get edited... And other ideas nogray, or anyone else??Will Quote Link to comment https://forums.phpfreaks.com/topic/14313-i-get-php-warning-then-my-script-doesnt-work/#findComment-56475 Share on other sites More sharing options...
ShogunWarrior Posted July 11, 2006 Share Posted July 11, 2006 If using preg_replace:[code]$mode[0] = '@'."\$maintenance = 0;".'@';[/code]Preg_Replace needs placeholders at the start/end of the pattern. Quote Link to comment https://forums.phpfreaks.com/topic/14313-i-get-php-warning-then-my-script-doesnt-work/#findComment-56501 Share on other sites More sharing options...
gamesmad Posted July 12, 2006 Author Share Posted July 12, 2006 I still cant get it to work, please can someone help??Will Quote Link to comment https://forums.phpfreaks.com/topic/14313-i-get-php-warning-then-my-script-doesnt-work/#findComment-56642 Share on other sites More sharing options...
heckenschutze Posted July 12, 2006 Share Posted July 12, 2006 try:[code]21 $settingscontent = file_get_contents($settingsdir);2223 $mode[0] = "/\$maintenance = 0;/";24 $newmode[0] = "\$maintenance = 2;";2526 $newsettingscontent = preg_replace($mode, $newmode, $settingscontent);[/code]you need to quote special regular expression characters, see: http://au3.php.net/manual/en/function.preg-quote.php Quote Link to comment https://forums.phpfreaks.com/topic/14313-i-get-php-warning-then-my-script-doesnt-work/#findComment-56647 Share on other sites More sharing options...
nogray Posted July 12, 2006 Share Posted July 12, 2006 in your suspend.phpwhen you echo the $newsettingscontent, is it the correct string?I notice you have the function file_put_contents_php4 () but you are not calling it anywhere in the script, so the file won't be edited.Let me know if this solves the problem. Quote Link to comment https://forums.phpfreaks.com/topic/14313-i-get-php-warning-then-my-script-doesnt-work/#findComment-56851 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.