Stream lining of php code

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
dgkindy
Forum Newbie
Posts: 15
Joined: Tue Sep 22, 2009 8:53 pm

Stream lining of php code

Post by dgkindy »

I have written some code in VB but now looking to convert to PHP. Now that I am going back over the code, I am rethinking that I should be able to make this code a bit more efficient. I have attached both the VB code and a sample of the text file that I am importing.

In general the process is repeated but due to the indenting, the locations of the data points move about slightly.

Code: Select all

[list]
|--331227643A           3899---POWER CABINET                         -------------------------------------------------EA --E--|
|  09-10-20 Plan.order 0005610522/Ord.*                                         1                1                            |
|                                                                                                                             |
||--3317643A-952       3899---ELEC-ASSY,EDR POWER SUPPLY,94KVA,4-STAGE-----------------------------------------------EA -----||
|| 09-09-21 POSched.ln 4501706708/00010                                         1                1                           ||
||                                                                                                                           ||
|||--3212292U-954       3899---ENCLOSURE,72X60X36,FS,N12,2DR,DUAL      ---------------------------------------------EA -----|||
|||09-09-14 SubctctReq 3317643A-952                                             1-               1-                         |||
|||09-09-21 POSched.ln 4501706708/00030              09-09-14 10                1                0                          |||
|||-------------------------------------------------------------------------------------------------------------------------|||
||                                                                                                                           ||
|||--3317643A-201       3899---TRANSFORMER,94KVA,4-STAGE,EDR           ---------------------------------------------EA -----|||
|||09-09-11 SubcStock  0000206186                                               1                1                          |||
|||09-09-14 SubctctReq 3317643A-952                                             1-               0                          |||
|||-------------------------------------------------------------------------------------------------------------------------|||
||                                                                                                                           ||
|| 09-10-02 Depend.req 3317643A                                                 1-               0                           ||
||---------------------------------------------------------------------------------------------------------------------------||
|                                                                                                                             |
|  09-10-22 SalesOrder 0003317643/000030/0001                                   1-               0                            |
|-----------------------------------------------------------------------------------------------------------------------------|
[/list]

Code: Select all

While Not EOF(1)
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    Do Until InStr(1, WholeLine, Line1) '"SalesOrder 000")  'Loops until the end of the module
        If InStr(1, WholeLine, Line7) Then      '||---
            '===============================================================================
            Do Until InStr(1, WholeLine, Line2)    '||--------||
                If InStr(1, WholeLine, Line8) Then      '|||--
                '***********************************************************************
                Do Until InStr(1, WholeLine, Line3)    '|||--------|||
                    If InStr(1, WholeLine, Line10) Then      '||||--
                    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    Do Until InStr(1, WholeLine, Line9)    '||||--------||||
                        If InStr(1, WholeLine, Line12) Then      '|||||--
                        '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        Do Until InStr(1, WholeLine, Line16)    '|||||--------|||||
                            If InStr(1, WholeLine, Line13) Then      '||||||--
                            '-------------------------------------------------------------------
                            Do Until InStr(1, WholeLine, Line17)    '||||||--------||||||
                                If InStr(1, WholeLine, Line13) Then      '||||||--
                                    Call HarvestPart(Mid(WholeLine, 9))
                                Else
                                    Call HarvestDetails(Mid(WholeLine, 8))
                                End If
                                Line Input #1, WholeLine
                            Loop
                            '-------------------------------------------------------------------
                            ElseIf InStr(1, WholeLine, Line12) Then '|||||--
                                Call HarvestPart(Mid(WholeLine, 8))
                            ElseIf InStr(1, WholeLine, Line21) Then '|||||    |||||
                                Call Bundle
                            Else
                                Call HarvestDetails(Mid(WholeLine, 6))
                            End If
                            Line Input #1, WholeLine
                        Loop
                        '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        ElseIf InStr(1, WholeLine, Line7) Then '||||--
                            Call HarvestPart(Mid(WholeLine, 7))
                        ElseIf InStr(1, WholeLine, Line20) Then '||||    ||||
                            Call Bundle
                        Else
                            Call HarvestDetails(Mid(WholeLine, 5))
                        End If
                        Line Input #1, WholeLine
                    Loop
                    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    ElseIf InStr(1, WholeLine, Line7) Then '||---
                        Call HarvestPart(Mid(WholeLine, 6))
                    ElseIf InStr(1, WholeLine, Line4) Then '|     |
                        Call Bundle
                    ElseIf InStr(1, WholeLine, Line11) Then '|||    |||
                        Call Bundle
                    Else
                        Call HarvestDetails(Mid(WholeLine, 4))
                    End If
                    Line Input #1, WholeLine
                Loop
                '***********************************************************************
                ElseIf InStr(1, WholeLine, Line7) Then '||---
                    Call HarvestPart(Mid(WholeLine, 5))
                ElseIf InStr(1, WholeLine, Line5) Then '||     ||
                    Call Bundle
                Else
                    Call HarvestDetails(Mid(WholeLine, 4))
                End If
                Line Input #1, WholeLine
            Loop
            '===============================================================================
        ElseIf InStr(1, WholeLine, Line1) Then '|-------|
            'Do nothing
        ElseIf Len(WholeLine) <= 1 Then 'Space
            'Do nothing
        ElseIf InStr(1, WholeLine, Line5) Then '||     ||
            'Do nothing
        ElseIf InStr(1, WholeLine, Line6) Then '|--
            Call Harvest(WholeLine)
        ElseIf InStr(1, WholeLine, Line4) Then '|     |
            Call Bundle
        Else
            Call HarvestDetails(Mid(WholeLine, 4))
        End If
        Line Input #1, WholeLine
    Loop
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    Call HarvestDetails(Mid(WholeLine, 4))
    Call Bundle
    Line Input #1, WholeLine
Wend
jjacob
Forum Newbie
Posts: 2
Joined: Wed Sep 23, 2009 3:06 pm

Re: Stream lining of php code

Post by jjacob »

The only thing that I can suggest will be to use Switch/Case instead of If/Elseif.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Stream lining of php code

Post by josh »

User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Stream lining of php code

Post by Ollie Saunders »

Post Reply