Jump to content

help please loop ??????????


rajmohan

Recommended Posts

i cannot put like this

 

i am having like this onle

 

one

two

three

four

five

six

 

like this i am having thousand what can i do i cant put in array

 

i should automatically take it as put it in array after one <br> then <br> like this it looks it is in txt file i have to do it as

 

"one","two", etc.......

Link to comment
https://forums.phpfreaks.com/topic/43335-help-please-loop/#findComment-210436
Share on other sites

Something like this?:

<?php

if(isset($_POST['cities']) && !empty($_POST['cities']))
{
    $cities_list = $_POST['cities'];

    // put each city on its own in an array.
    $cities = explode("\n", $cities_list);

    // now we format how we want the cities to be added to the txt file
    $city_list = '';

    foreach($cities as $city)
    {
        $city_list .= '"' . trim($city) . '", ';
    }

    //clean up the cities_listed sting
    $city_list = substr($city_list, 0, (strlen($city_list)-2));

    echo 'Cities to be added:<br />' . $city_list . '<br /><hr />';

    // open file read for writing
    $city_file = fopen('cities.txt', 'a');

    // make sure file is writeable
    if(is_writable('cities.txt'))
    {
        // write cities list to file
        fwrite($city_file, $city_list . "\r\n");

        // close the file
        fclose($city_file);
    }
    else
    {
        echo 'Unable to write to file!';
    }

}

?>
<form action="" method="post">
Cities:<br /><textarea name="cities"></textarea><br />
<input type="submit" name="submit" value="Add Cities!" />
</form>

Add each city on a new line in the textarea. Submit the form it will format the string to be entered into the text file for you, the format entered into the text file would be like this:

"city1, "city2", "city3", "exct...."

 

It will add each group of cities you submit on a new line in the text file too.

Link to comment
https://forums.phpfreaks.com/topic/43335-help-please-loop/#findComment-210458
Share on other sites

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.