Find and replace in PHP

Discuss the development of future releases of phpBB (phpBB 3.x minor releases) and MODing/Coding related questions.
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Find and replace in PHP

Postby harmlessgoat22 » 08 Jun 2008, 15:16

How can I use PHP to open another PHP file, find a line, and replace it with something else??? If it helps, here's the document that needs to be opened...
$phpbb_root_path . 'includes/functions_alpha.' . $phpEx
Here are the two lines that need to be found...

$select_sidebar = 8;
and
$select_sidebar = 9;

These lines are not right next to each other.
And I need them to be replaced with...
$select_sidebar = {$module_id1};
and
$select_sidebar = {$module_id2};

Please note that I don't want it to say $select_sidebar = $module_id1, I want it to say $select_sidebar = (and then the value of $module_id1).

So, any help is appreciated.

That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever

User avatar
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Find and replace in PHP

Postby igorw » 08 Jun 2008, 15:51

Last edited by igorw on 12 Jan 2015, 23:59, edited 2 times in total.
Reason: write needs to be fwrite, thanks leory for calling me a nub

- we're poor!

harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Re: Find and replace in PHP

Postby harmlessgoat22 » 08 Jun 2008, 16:11

does this only work in PHP5???

That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever

User avatar
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Find and replace in PHP

Postby igorw » 08 Jun 2008, 16:39

Nope, works in 4.3 as well. If you were using PHP5 only, you could however use file_put_contents().

- we're poor!

harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Re: Find and replace in PHP

Postby harmlessgoat22 » 08 Jun 2008, 17:06

Nope, I want it to work with everything phpBB3 works with.

That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever


[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Return to “phpBB Development discussion”

Who is online

Users browsing this forum: No registered users and 19 guests