Jump to content


Photo

I get PHP Warning, then my script doesnt work.


  • Please log in to reply
8 replies to this topic

#1 gamesmad

gamesmad
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 11 July 2006 - 06:04 PM

I get the error -

Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /home/gamesm/public_html/freeforums/suspend.php on line 26

Lines 21 - 26 go like this -

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);

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

Will

#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 11 July 2006 - 06:39 PM

I think you need a \ before the $ in your mode strings
23  $mode[0] = "\$maintenance = 0;";
24  $newmode[0] = "\$maintenance = 2;";

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.

NoGray.com


#3 gamesmad

gamesmad
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 11 July 2006 - 07:14 PM

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]

#4 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 11 July 2006 - 08:01 PM

you need to add a \ infront of the $ in your strings, otherwise the script will look for the $maintenance value

$newsettingscontent = str_replace("\$maintenance = 0;", "\$maintenance = 2;", "$settingscontent");

NoGray.com


#5 gamesmad

gamesmad
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 11 July 2006 - 10:19 PM

Now the file doesnt get edited...  And other ideas nogray, or anyone else??

Will

#6 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 11 July 2006 - 11:27 PM

If using preg_replace:
$mode[0] = '@'."\$maintenance = 0;".'@';

Preg_Replace needs placeholders at the start/end of the pattern.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#7 gamesmad

gamesmad
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 12 July 2006 - 08:08 AM

I still cant get it to work, please can someone help??

Will

#8 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 12 July 2006 - 08:38 AM

try:

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);

you need to quote special regular expression characters, see: http://au3.php.net/m....preg-quote.php

#9 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 12 July 2006 - 05:36 PM

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.

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users