Lets say i made a mod to an existing scrip and want to implement it automatically. Im trying to make an installation script that would find some php files, open them, search for a specific line of code and replace it with another line in some cases and in some cases just insert some code below that line without replacing anything. Im up to the part of the file opening, but Im Stuck in the search. I can find ONE line of code, but in some cases I need to find a whole block. How can I find a specific block of code, and since im no expert, does the tabs in front of the code matters? I guess they do, but im not sure.
Let me show you an example of what im trying to do....
The first case is to find a single line of code like this...
Code: Select all
$userinfo['ship_country_list'] = getoptionlist('state_country', 'abb', 'name', 'WHERE type=\'' . COUNTRY . '\'', ($userinfo[ship_country] == "") ? $settings[country] : $userinfo[ship_country], 'name');
Code: Select all
////////////// Start Account Type - Changes Required/////////////
$userinfo['account_type'] = getaccounttype($userinfo[group_in]);
$userinfo['account_type_list'] = getoptionlist('groups', 'id', 'name', 'WHERE visible=\'1\' ', $userinfo[group_in], 'name', 1);
////////////// End Account Type - Changes Required/////////////** Notice the tabs in front of the code, since the original script file is formated like that i don´t know how to work arround this.
Code: Select all
while ($field = $DB_site->fetch_assoc($result))
{
if ($field['Field'] == 'password') $vars[password] = md5($vars[password]);
if (isset($vars[$field['Field']])) $query .= " `" . $field['Field'] . "`='" . sf($vars[$field['Field']]) . "',";
}
$query .= " `group_in`='" . $settings[defaultgroup] . "'";Code: Select all
////////////// Start Account Type - Changes Required/////////////
while ($field = $DB_site->fetch_assoc($result))
{
if ($field['Field'] == 'password') $vars[password] = md5($vars[password]);
if ($field['Field'] == 'username')
{
if (isset($vars[$field['Field']])) $query .= " `" . $field['Field'] . "`='" . sf($vars[$field['Field']]) . "'";
}else{
if ($field['Field'] == 'group_in')
{
if (getoptionlist('groups', 'id', 'name', 'WHERE visible=\'1\' ', "", 'name', 0) == "")
{
$query .= ", `" . $field['Field'] . "`='" . $settings[defaultgroup] . "'";
}else{
if (isset($vars[$field['Field']])) $query .= ", `" . $field['Field'] . "`='" . sf($vars[$field['Field']]) . "'";
}
}else{
if (isset($vars[$field['Field']])) $query .= ", `" . $field['Field'] . "`='" . sf($vars[$field['Field']]) . "'";
}
}
}
////////////// End Account Type - Changes Required/////////////