1 Replies - 651 Views - Last Post: 15 June 2011 - 01:54 PM Rate Topic: -----

#1 peytonrs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-June 11

how do I use preg_replace correctly?

Posted 15 June 2011 - 01:50 PM

I'm making an installation script for one of my PHP software suites and I need to edit a variable in a central config.php file. I've made this code below but I am sure that this is the incorrect way to use REGEX.

		$username = $_POST['un'];
		$password = $_POST['pw'];
		$f = fopen("config.php", "w+");
		$read = fread($f, 3013004);
		$replaced = preg_replace('$config[\'USERNAME\'] = "{1}";', $username, $read);



I've read the regex documentation however it provides little help for PREG_REPLACE in this situation. Can someone either guide me in a direction on how I should properly use this for my situation or attempt to explain what I should do for it?

Thanks,
peyton

Is This A Good Question/Topic? 0
  • +

Replies To: how do I use preg_replace correctly?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3490
  • View blog
  • Posts: 10,058
  • Joined: 08-June 10

Re: how do I use preg_replace correctly?

Posted 15 June 2011 - 01:54 PM

you’ve forgotten the delimiter characters for the regex string.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1