Jump to content

Php List Box Loop! Help please!


Deanznet

Recommended Posts

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

 

$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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.