Jump to content

Archived

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

gamesmad

I get PHP Warning, then my script doesnt work.

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
If using preg_replace:
[code]
$mode[0] = '@'."\$maintenance = 0;".'@';
[/code]

Preg_Replace needs placeholders at the start/end of the pattern.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.