pintas Posted May 14, 2011 Share Posted May 14, 2011 I'm trying to edit this file in PHP through AutoIt, I just want to change some aspects of the file like the password for example, but i can't do this. It seems far to complicated for my basic knowledge of AutoIt. Here's an example of the file i'm trying to change: <?php $PUBLISHED_FOLDERS = array( "1" => array("name" => "Folder A", "path" => "/foo/bar"), "2" => array("name" => "Folder B", "path" => "/foo/bay"), "3" => array("name" => "Folder C", "path" => "/foo/bat") ); $USERS = array( "1" => array("name" => "User 1", "password" => "foo", "default_permission" => "rw", "folders" => array( "1" => NULL, "2" => NULL, "3" => NULL )), "2" => array("name" => "User 2", "password" => "bar", "default_permission" => "ro", "folders" => array( "1" => "Custom name for Folder A", "2" => NULL )) ); ?> How can i replace the password 'foo' (for ex.) with '123456'? Can this be done? Link to comment Share on other sites More sharing options...
hannes08 Posted May 14, 2011 Share Posted May 14, 2011 Hi pintas, did you try StringReplace? Or you can get the password with _StringBetween($string, 'password" => "', '"') Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
wakillon Posted May 14, 2011 Share Posted May 14, 2011 (edited) For this file in PHP, you can use _ReplaceStringInFile function_ReplaceStringInFile ( 'c:\file.php', '"foo"', '"123456"' ) Edited May 14, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
hannes08 Posted May 14, 2011 Share Posted May 14, 2011 For this file in PHP, you can use _ReplaceStringInFile functionWow, I didn't knew that one. But then again so far I had no similar "problem". Maybe this will happen some day. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
wakillon Posted May 14, 2011 Share Posted May 14, 2011 @HannesWhat is interesting when we help others, is to discover different solutions from those that we know ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
hannes08 Posted May 14, 2011 Share Posted May 14, 2011 @HannesWhat is interesting when we help others, is to discover different solutions from those that we know ! Hell, yes. I think there are only few times I read a solution form someone else where I can't learn from. I'm especially insterested in how to do things more efficiently. So for example using a single _ReplaceStringInFile instead of having to read the file replacing and writing it again. That's just awesome. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
pintas Posted May 14, 2011 Author Share Posted May 14, 2011 Thanks all for your answers, but if i have two or more users with the same password in that file, if i StringReplace to change that password, wouldn't that change all the identical passwords? Link to comment Share on other sites More sharing options...
wakillon Posted May 14, 2011 Share Posted May 14, 2011 Thanks all for your answers, but if i have two or more users with the same password in that file, if i StringReplace to change that password, wouldn't that change all the identical passwords? Right ! So use this _ReplaceStringInFile ( 'c:\file.php', '"User 1", "password" => "foo"', '"User 1", "password" => "123456"' ) And don't say me that user can have same names ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
hannes08 Posted May 14, 2011 Share Posted May 14, 2011 Thanks all for your answers, but if i have two or more users with the same password in that file, if i StringReplace to change that password, wouldn't that change all the identical passwords? ... Then you'll need to loop through that file and look for the lines where the user names match and do the replace there. E.g. #include <file.au3> Dim $a_contents _FileReadToArray("phpfile.php", $a_contents) For $i = 1 To $a_contents[0] If StringInStr($a_contents[$i], "UserThatShouldMatch") Then $a_contents[$i] = StringReplace($a_contents[$i], "foo", "123456") EndIf _FileWriteFromArray("phpfile.php", $a_contents, 1) Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
pintas Posted May 14, 2011 Author Share Posted May 14, 2011 Right ! So use this _ReplaceStringInFile ( 'c:\file.php', '"User 1", "password" => "foo"', '"User 1", "password" => "123456"' ) And don't say me that user can have same names ! eheheh... No, that won't happen. Thanks man! Now i understand. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now