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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.