import re with open('register.php', 'r') as f: content = f.read() # 1 content = content.replace(" 'plate_no' => '',", " 'plate_no' => '',\n 'bank_account' => '',\n 'bank_name' => '',\n 'bank_branch' => '',") # 2 content = content.replace(" 'plate_no' => trim($_POST['plate_no'] ?? ''),", " 'plate_no' => trim($_POST['plate_no'] ?? ''),\n 'bank_account' => trim($_POST['bank_account'] ?? ''),\n 'bank_name' => trim($_POST['bank_name'] ?? ''),\n 'bank_branch' => trim($_POST['bank_branch'] ?? ''),") # 3 content = content.replace(" $plateNo = trim($_POST['plate_no'] ?? '');", " $plateNo = trim($_POST['plate_no'] ?? '');\n $bankAccount = trim($_POST['bank_account'] ?? '');\n $bankName = trim($_POST['bank_name'] ?? '');\n $bankBranch = trim($_POST['bank_branch'] ?? '');") # 4 s4 = " if ($truckType === '' || $loadCapacity === '' || $plateNo === '') {\n $errors[] = 'Please complete truck details.';\n } elseif (!is_numeric($loadCapacity) || (float)$loadCapacity <= 0) {" r4 = " if ($truckType === '' || $loadCapacity === '' || $plateNo === '') {\n $errors[] = 'Please complete truck details.';\n } elseif ($bankAccount === '' || $bankName === '' || $bankBranch === '') {\n $errors[] = 'Please complete bank account details.';\n } elseif (!is_numeric($loadCapacity) || (float)$loadCapacity <= 0) {" content = content.replace(s4, r4) # 5 s5 = " $ownerStmt = $pdo->prepare( \"INSERT INTO truck_owner_profiles (user_id, phone, country_id, city_id, address_line, truck_type, load_capacity, plate_no, id_card_path, truck_pic_path, registration_path)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\" ); $ownerStmt->execute([ $userId, $phone, $countryId, $cityId, $addressLine, $truckType, $loadCapacity, $plateNo, json_encode($idCardPaths, JSON_UNESCAPED_SLASHES), $truckPic, json_encode($regPaths, JSON_UNESCAPED_SLASHES), ]);" r5 = " $ownerStmt = $pdo->prepare( \"INSERT INTO truck_owner_profiles (user_id, phone, country_id, city_id, address_line, truck_type, load_capacity, plate_no, bank_account, bank_name, bank_branch, id_card_path, truck_pic_path, registration_path)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\" ); $ownerStmt->execute([ $userId, $phone, $countryId, $cityId, $addressLine, $truckType, $loadCapacity, $plateNo, $bankAccount, $bankName, $bankBranch, json_encode($idCardPaths, JSON_UNESCAPED_SLASHES), $truckPic, json_encode($regPaths, JSON_UNESCAPED_SLASHES), ]);" content = content.replace(s5, r5) # 6 s6 = " 'plate_no' => ''," r6 = " 'plate_no' => '',\n 'bank_account' => '',\n 'bank_name' => '',\n 'bank_branch' => ''," # careful not to replace the first one again parts = content.split(s6) if len(parts) == 3: content = parts[0] + s6 + parts[1] + r6 + parts[2] elif len(parts) == 2: # meaning the first one was already replaced by s1/r1 (which is the same search string!) # wait, s1 and s6 are exactly the same? # No, s1 is " 'plate_no' => ''," and s6 is " 'plate_no' => ''," (more spaces) content = parts[0] + r6 + parts[1] # 7 s7 = "
\">
" r7 = "
\">

Bank Details for Payouts

\" required>
\" required>
\" required>
" content = content.replace(s7, r7) with open('register.php', 'w') as f: f.write(content) print("Replaced in register.php")