Jump to content

I get PHP Warning, then my script doesnt work.


gamesmad

Recommended Posts

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);
22
23  $mode[0] = "$maintenance = 0;";
24  $newmode[0] = "$maintenance = 2;";
25
26  $newsettingscontent = preg_replace($mode, $newmode, $settingscontent);[/code]

Any idea where I am going wrong??  Its stopping my script from working...

Will
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 $maintenance

Also, since you are not using any reg expressions, it's best to use str_replace() because it runs faster and uses less resources.
try:

[code]21  $settingscontent = file_get_contents($settingsdir);
22
23  $mode[0] = "/\$maintenance = 0;/";
24  $newmode[0] = "\$maintenance = 2;";
25
26  $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
in your suspend.php

when 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.