SHOW:
|
|
- or go back to the newest paste.
| 1 | //FILE NAME | |
| 2 | $filename = "base.sqf"; | |
| 3 | //OPEN FILE | |
| 4 | $handle = fopen($filename, "r"); | |
| 5 | //GET FILE CONTENTS INTO STRING | |
| 6 | $contents = fread($handle, filesize($filename)); | |
| 7 | //CLOSE FILE | |
| 8 | fclose($handle); | |
| 9 | ||
| 10 | //TEXT TO SEARCH FOR | |
| 11 | $findme = "AH1Z"; | |
| 12 | ||
| 13 | //GET POSITION OF TEXT/CHECK IF EXISTS IN FILE CONTENTS STRING | |
| 14 | $pos = strpos($contents, $findme); | |
| 15 | ||
| 16 | ||
| 17 | //IF RESULT NOT FALSE | |
| 18 | if ($pos === false) {
| |
| 19 | echo "The string '$findme' was not found in the string '$contents'"; | |
| 20 | } else {
| |
| 21 | //FOUND THE AH1Z! | |
| 22 | echo "The string '$findme' was found in the string!"; | |
| 23 | echo " and exists at position $pos"; | |
| 24 | ||
| 25 | ||
| 26 | //NOW WE NEED TO FIND THE CLOSING }; OF THIS VEHICLE | |
| 27 | $findme = "};"; | |
| 28 | - | //THIS POSITION IS THE END OF THAT VEHICLES SECTION |
| 28 | + | //THIS POSITION IS THE END OF THAT VEHICLES SECTION, USING $POS AS THE STARTING OFFSET TO START SEARCHING FROM |
| 29 | - | $pos2 = strpos($contents, $findme2); |
| 29 | + | $pos2 = strpos($contents, $findme2, $pos); |
| 30 | ||
| 31 | ||
| 32 | //NOW WE CAN USE FSEEK TO SEEK TO 1 CHARACTER BEFORE POS2 | |
| 33 | $file = fopen($filename, "c"); | |
| 34 | fseek(($file, -3, ($pos2 - 1)); | |
| 35 | fwrite($file, "VEHICLE REMOVE WEAPON BLA BLA"); | |
| 36 | fclose($file); | |
| 37 | } |