Deanznet Posted September 20, 2010 Share Posted September 20, 2010 Okay. Lets say i have a list box. <select name="drop1" id="Select1" size="4" multiple="multiple"> <option value="1">item 1</option> <option value="2">item 2</option> <option value="3">item 3</option> <option value="4">item 4</option> <option value="0">All</option> </select> Now what i need it to do is open a file and replace the string [Replace] with whats in the list box. But it has to loop through everything in the list box understand? So How can i make it so that after it replaces 2 strings it gose to the next list item ect. after it replaces 2 more strings it goes to the next. So basically every 2 strings it will switch! Please help! here my code so far. <?php $fh = fopen(" myfile.txt", "r+"); if($fh==false) die("unable to create file"); ?> Please help! Link to comment https://forums.phpfreaks.com/topic/213930-php-list-box-loop-help-please/ Share on other sites More sharing options...
Deanznet Posted September 27, 2010 Author Share Posted September 27, 2010 BUMP Link to comment https://forums.phpfreaks.com/topic/213930-php-list-box-loop-help-please/#findComment-1116312 Share on other sites More sharing options...
AbraCadaver Posted September 27, 2010 Share Posted September 27, 2010 $file = file_get_contents('myfile.txt');foreach($_POST['drop1'] as $replace) {$file = preg_replace('#\[Replace\]#', $replace, $file, 2);} So it will replace the first two [Replace] with 1 and the next two with 2, etc... Link to comment https://forums.phpfreaks.com/topic/213930-php-list-box-loop-help-please/#findComment-1116317 Share on other sites More sharing options...
Deanznet Posted September 27, 2010 Author Share Posted September 27, 2010 Thats it right their? That simple huh? Link to comment https://forums.phpfreaks.com/topic/213930-php-list-box-loop-help-please/#findComment-1116359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.