locked
Read 4 lines from a text file, assign data from each line to a variable. RRS feed

  • Question

  • I created a web page asking for user input. my php exports the data to a text file, each input on a separate line.

    1. Servername

    2. End_date

    3. Startup_time

    How do i read the file and assign each of these lines to variables such as $server $end_date and $satrtup_time?

    Thank you for any help

    Monday, March 5, 2018 10:51 PM

Answers

  • Also a good PowerShell technique to learn:

    $server_name, $end_date, $startup_time = get-content C:\path\to\your\file.txt | select -first 3


    \_(ツ)_/



    • Marked as answer by Thor Reichelt Wednesday, March 7, 2018 3:20 AM
    • Edited by jrv Wednesday, March 7, 2018 3:20 AM
    Wednesday, March 7, 2018 3:19 AM
  • How this works ...

    PS D:\scripts> $a,$b,$c,$d,$rest_of_array = 1,2,3,4,5,6,7,8,9
    PS D:\scripts> $a
    1
    PS D:\scripts> $b
    2
    PS D:\scripts> $c
    3
    PS D:\scripts> $rest_of_array
    5
    6
    7
    8
    9
    PS D:\scripts>
    


    \_(ツ)_/

    • Marked as answer by Thor Reichelt Wednesday, March 7, 2018 3:25 AM
    Wednesday, March 7, 2018 3:23 AM

All replies