{"id":13592141,"url":"https://github.com/php-edifact/edifact","last_synced_at":"2026-01-11T16:51:38.093Z","repository":{"id":11530496,"uuid":"14014481","full_name":"php-edifact/edifact","owner":"php-edifact","description":"Tools to process EDI messages in UN/EDIFACT format","archived":false,"fork":false,"pushed_at":"2024-10-21T07:36:07.000Z","size":1960,"stargazers_count":272,"open_issues_count":3,"forks_count":87,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-10-21T10:41:20.860Z","etag":null,"topics":["edi","edifact","un-edifact"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-edifact.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-10-31T11:00:16.000Z","updated_at":"2024-10-21T07:36:12.000Z","dependencies_parsed_at":"2022-08-29T05:20:14.554Z","dependency_job_id":"844e4372-8442-4fde-8aa6-3abd231a157e","html_url":"https://github.com/php-edifact/edifact","commit_stats":{"total_commits":210,"total_committers":30,"mean_commits":7.0,"dds":0.5857142857142856,"last_synced_commit":"053f8db9a2a44e6ab763e3e4262d519949360647"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-edifact%2Fedifact","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-edifact%2Fedifact/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-edifact%2Fedifact/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-edifact%2Fedifact/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-edifact","download_url":"https://codeload.github.com/php-edifact/edifact/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223346544,"owners_count":17130459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["edi","edifact","un-edifact"],"created_at":"2024-08-01T16:01:06.167Z","updated_at":"2026-01-11T16:51:38.064Z","avatar_url":"https://github.com/php-edifact.png","language":"PHP","funding_links":[],"categories":["Libraries"],"sub_categories":["PHP"],"readme":"edifact\n=======\n\nTools to process EDI messages in UN/EDIFACT format\n\nSupported syntax is version 3.\n\nIt's provided in a Composer package:\n\n`composer require sabas/edifact`\n\nThe mapping XML files are provided in a separate package:\n\n`composer require php-edifact/edifact-mapping`\n\nEDI\\Parser\n------------------\nGiven an EDI message checks the syntax, outputs errors and returns the message as a multidimensional array.\n\n**INPUT**\n```php\n$p = new EDI\\Parser();\n$p-\u003eload($location);     // a local path to a file or a URL (if file_get_contents() allows for remote access)\n$p-\u003eloadString($string); // a full message (single line text)\n$p-\u003eloadArray($array);   // an array of strings (one segment per entry)\n```\n\n**OUTPUT**\n\nErrors\n```php\n$c-\u003eerrors();\n```\nArray\n```php\n$c-\u003eget();\n```\n\n\nEDI\\Encoder\n------------------\nGiven a multidimensional array (formatted as the output of the parser), returns an EDI string, optionally one segment per line.\n\n**INPUT**\n```php\n$c = new EDI\\Encoder($x, $compact = true);\n```\n`$x` is a multidimensional array where first dimension is the EDI segment, second contains elements:\n* single value\n* array (representing composite elements)\n\n`$compact` is a boolean, if you need a segment per line. Set to false to enable wrapped lines.\n\nOR\n```php\n$c = new EDI\\Encoder();\n$c-\u003eencode($array, false);\n```\n\n**OUTPUT**\n```php\n$c-\u003eget(); // returns String\n```\n\nEDI\\Analyser\n------------------\nCreate human-readable, structured text with comments from `segments.xml`.\nRequires the EDI\\Mapping package.\n\n```php\n        $parser = new EDI\\Parser();\n        $parser-\u003eload($file);\n        $segments = $parser-\u003egetRawSegments();\n        $parsed = $parser-\u003eget();\n        $analyser = new EDI\\Analyser();\n        $mapping = new EDI\\MappingProvider('D95B');\n        $analyser-\u003eloadSegmentsXml($mapping-\u003egetSegments());\n        $analyser-\u003eloadSegmentsXml($mapping-\u003egetServiceSegments(), false);\n        $analyser-\u003eloadMessageXml($mapping-\u003egetMessage('coparn'));\n        $analyser-\u003eloadCodesXml($mapping-\u003egetCodes());\n        $analyser-\u003edirectory = 'D95B';\n        $result = $analyser-\u003eprocess($parsed, $segments);                   \n\n```\n* `$file` is the path to orginal EDI message file\n\n### Example INPUT \n```text\nUNA:+,? '\nUNB+UNOA:1+MAEU+LVRIXBCT+200813:0816+1412605'\nUNH+141260500001+COPARN:D:95B:UN'\nBGM+12+20200813081626+9'\nRFF+BN:204549739'\nNAD+CA+MAE:172:20'\nEQD+CN++45G1:102:5+2+2+4'\nRFF+BN:204549739'\nRFF+SQ:7G3JTL39O0M3B'\nTMD+++2'\nDTM+201:202008130000:203'\nLOC+98+LVRIX:139:6+RIGA TERMINAL:TER:ZZZ'\nCNT+16:1'\nUNT+12+141260500001'\nUNZ+1+1412605'\n```\n\n### Example Output \n```text\n\nUNA:+,? '\nUNB - InterchangeHeader\n  (To start, identify and specify an interchange)\n  [0] UNOA,1\n      unb1 - syntaxIdentifier\n      Syntax identifier\n    [0] UNOA\n        id: unb11 - syntaxIdentifier\n        Syntax identifier\n        type: a\n        required: true\n        length: 4\n    [1] 1\n        id: unb12 - syntaxVersionNumber\n        Syntax version number\n        type: n\n        required: true\n        length: 1\n  [1] MAEU\n      unb2 - interchangeSender\n      Interchange sender\n  [2] LVRIXBCT\n      unb3 - interchangeRecipient\n      Interchange recipient\n  [3] 200813,0816\n      unb4 - dateTimePreparation\n      Date Time of preparation\n    [0] 200813\n        id: unb41 - date\n        \n        type: n\n        required: true\n        length: 6\n    [1] 0816\n        id: unb42 - time\n        \n        type: n\n        required: true\n        length: 4\n  [4] 1412605\n      unb5 - interchangeControlReference\n      \n\nUNB+UNOA:1+MAEU+LVRIXBCT+200813:0816+1412605'\nUNH - messageHeader http://www.unece.org/trade/untdid/d95b/trsd/trsdunh.htm\n  (To head, identify and specify a message.)\n  [0] 141260500001\n      unh1 - messageReferenceNumber\n      \n  [1] COPARN,D,95B,UN\n      unh2 - messageType\n      \n    [0] COPARN\n        id: unh21 - messageType\n        \n        type: an\n        maxlen: 6\n        required: true\n    [1] D\n        id: unh22 - messageVersion\n        \n        type: an\n        maxlen: 3\n        required: true\n    [2] 95B\n        id: unh23 - messageRelease\n        \n        type: an\n        maxlen: 3\n        required: true\n    [3] UN\n        id: unh24 - controllingAgency\n        \n        type: an\n        maxlen: 3\n        required: true\n\nUNH+141260500001+COPARN:D:95B:UN'\nBGM - beginningOfMessage http://www.unece.org/trade/untdid/d95b/trsd/trsdbgm.htm\n  (To indicate the type and function of a message and to transmit the\n  identifying number.)\n  [0] 12\n      C002 - documentmessageName\n      Identification of a type of document/message by code or name. Code\n      preferred.\n  [1] 20200813081626\n      1004 - documentmessageNumber\n      Reference number assigned to the document/message by the issuer.\n  [2] 9\n      1225 - messageFunctionCoded\n      Code indicating the function of the message.\n\nBGM+12+20200813081626+9'\nRFF - reference http://www.unece.org/trade/untdid/d95b/trsd/trsdrff.htm\n  (To specify a reference.)\n  [0] BN,204549739\n      C506 - reference\n      Identification of a reference.\n    [0] BN - Booking reference number\n        id: 1153 - referenceQualifier\n        Code giving specific meaning to a reference segment or a reference\n        number.\n        type: an\n        maxlen: 3\n        required: true\n    [1] 204549739\n        id: 1154 - referenceNumber\n        Identification number the nature and function of which can be\n        qualified by an entry in data element 1153 Reference qualifier.\n        type: an\n        maxlen: 35\n\nRFF+BN:204549739'\nNAD - nameAndAddress http://www.unece.org/trade/untdid/d95b/trsd/trsdnad.htm\n  (To specify the name/address and their related function, either by CO82 only\n  and/or unstructured by CO58 or structured by CO80 thru 3207. be permitted\n  to use the ADR segment and/or the PNA segment.  After the conclusion of the\n  Brazil JRT (scheduled for April 1996), this NAD segment shall NO LONGER BE\n  PERMITTED FOR USE IN ANY NEW MESSAGES submitted for Status 1 in the\n  UN/EDIFACT Directories. This means that either the ADR and/or the PNA\n  segments shall be used in place of this NAD segment by the message\n  designers. (See Rapporteurs' decision on the proposed ADR \u0026 PNA segments\n  and the existing NAD segment - Sydney, April 1995).)\n  [0] CA\n      3035 - partyQualifier\n      Code giving specific meaning to a party.\n  [1] MAE,172,20\n      C082 - partyIdentificationDetails\n      Identification of a transaction party by code.\n    [0] MAE\n        id: 3039 - partyIdIdentification\n        Code identifying a party involved in a transaction.\n        type: an\n        maxlen: 35\n        required: true\n    [1] 172 - Carrier code\n        id: 1131 - codeListQualifier\n        Identification of a code list.\n        type: an\n        maxlen: 3\n    [2] 20 - BIC (Bureau International des Containeurs)\n        id: 3055 - codeListResponsibleAgencyCoded\n        Code identifying the agency responsible for a code list.\n        type: an\n        maxlen: 3\n\nNAD+CA+MAE:172:20'\nEQD - equipmentDetails http://www.unece.org/trade/untdid/d95b/trsd/trsdeqd.htm\n  (To identify a unit of equipment.)\n  [0] CN\n      8053 - equipmentQualifier\n      Code identifying type of equipment.\n  [1] \n      C237 - equipmentIdentification\n      Marks (letters and/or numbers) identifying equipment used for transport\n      such as a container.\n  [2] 45G1,102,5\n      C224 - equipmentSizeAndType\n      Code and/or name identifying size and type of equipment used in\n      transport. Code preferred.\n    [0] 45G1\n        id: 8155 - equipmentSizeAndTypeIdentification\n        Coded description of the size and type of equipment e.g. unit load\n        device.\n        type: an\n        maxlen: 10\n    [1] 102 - Size and type\n        id: 1131 - codeListQualifier\n        Identification of a code list.\n        type: an\n        maxlen: 3\n    [2] 5 - ISO (International Organization for Standardization)\n        id: 3055 - codeListResponsibleAgencyCoded\n        Code identifying the agency responsible for a code list.\n        type: an\n        maxlen: 3\n  [3] 2\n      8077 - equipmentSupplierCoded\n      To indicate the party that is the supplier of the equipment.\n  [4] 2\n      8249 - equipmentStatusCoded\n      Indication of the action related to the equipment.\n  [5] 4\n      8169 - fullemptyIndicatorCoded\n      To indicate the extent to which the equipment is full or empty.\n\nEQD+CN++45G1:102:5+2+2+4'\nRFF - reference http://www.unece.org/trade/untdid/d95b/trsd/trsdrff.htm\n  (To specify a reference.)\n  [0] BN,204549739\n      C506 - reference\n      Identification of a reference.\n    [0] BN - Booking reference number\n        id: 1153 - referenceQualifier\n        Code giving specific meaning to a reference segment or a reference\n        number.\n        type: an\n        maxlen: 3\n        required: true\n    [1] 204549739\n        id: 1154 - referenceNumber\n        Identification number the nature and function of which can be\n        qualified by an entry in data element 1153 Reference qualifier.\n        type: an\n        maxlen: 35\n\nRFF+BN:204549739'\nRFF - reference http://www.unece.org/trade/untdid/d95b/trsd/trsdrff.htm\n  (To specify a reference.)\n  [0] SQ,7G3JTL39O0M3B\n      C506 - reference\n      Identification of a reference.\n    [0] SQ - Container sequence number\n        id: 1153 - referenceQualifier\n        Code giving specific meaning to a reference segment or a reference\n        number.\n        type: an\n        maxlen: 3\n        required: true\n    [1] 7G3JTL39O0M3B\n        id: 1154 - referenceNumber\n        Identification number the nature and function of which can be\n        qualified by an entry in data element 1153 Reference qualifier.\n        type: an\n        maxlen: 35\n\nRFF+SQ:7G3JTL39O0M3B'\nTMD - transportMovementDetails http://www.unece.org/trade/untdid/d95b/trsd/trsdtmd.htm\n  (To specify transport movement details for a goods item or equipment.)\n  [0] \n      C219 - movementType\n      Description of type of service for movement of cargo.\n  [1] \n      8332 - equipmentPlan\n      Description indicating equipment plan, e.g. FCL or LCL.\n  [2] 2\n      8341 - haulageArrangementsCoded\n      Specification of the type of equipment haulage arrangements.\n\nTMD+++2'\nDTM - datetimeperiod http://www.unece.org/trade/untdid/d95b/trsd/trsddtm.htm\n  (To specify date, and/or time, or period.)\n  [0] 201,202008130000,203\n      C507 - datetimeperiod\n      Date and/or time, or period relevant to the specified date/time/period\n      type.\n    [0] 201 - Pick-up date/time of equipment\n        id: 2005 - datetimeperiodQualifier\n        Code giving specific meaning to a date, time or period.\n        type: an\n        maxlen: 3\n        required: true\n    [1] 202008130000\n        id: 2380 - datetimeperiod\n        The value of a date, a date and time, a time or of a period in a\n        specified representation.\n        type: an\n        maxlen: 35\n    [2] 203 - CCYYMMDDHHMM\n        id: 2379 - datetimeperiodFormatQualifier\n        Specification of the representation of a date, a date and time or of\n        a period.\n        type: an\n        maxlen: 3\n\nDTM+201:202008130000:203'\nLOC - placelocationIdentification http://www.unece.org/trade/untdid/d95b/trsd/trsdloc.htm\n  (To identify a country/place/location/related location one/related location\n  two.)\n  [0] 98\n      3227 - placelocationQualifier\n      Code identifying the function of a location.\n  [1] LVRIX,139,6\n      C517 - locationIdentification\n      Identification of a location by code or name.\n    [0] LVRIX\n        id: 3225 - placelocationIdentification\n        Identification of the name of place/location, other than 3164 City\n        name.\n        type: an\n        maxlen: 25\n    [1] 139 - Port\n        id: 1131 - codeListQualifier\n        Identification of a code list.\n        type: an\n        maxlen: 3\n    [2] 6 - UN/ECE (United Nations - Economic Commission for Europe)\n        id: 3055 - codeListResponsibleAgencyCoded\n        Code identifying the agency responsible for a code list.\n        type: an\n        maxlen: 3\n  [2] RIGA TERMINAL,TER,ZZZ\n      C519 - relatedLocationOneIdentification\n      Identification the first related location by code or name.\n    [0] RIGA TERMINAL\n        id: 3223 - relatedPlacelocationOneIdentification\n        Specification of the first related place/location by code.\n        type: an\n        maxlen: 25\n    [1] TER\n        id: 1131 - codeListQualifier\n        Identification of a code list.\n        type: an\n        maxlen: 3\n    [2] ZZZ - Mutually defined\n        id: 3055 - codeListResponsibleAgencyCoded\n        Code identifying the agency responsible for a code list.\n        type: an\n        maxlen: 3\n\nLOC+98+LVRIX:139:6+RIGA TERMINAL:TER:ZZZ'\nCNT - controlTotal http://www.unece.org/trade/untdid/d95b/trsd/trsdcnt.htm\n  (To provide control total.)\n  [0] 16,1\n      C270 - control\n      Control total for checking integrity of a message or part of a message.\n    [0] 16 - Total number of equipment\n        id: 6069 - controlQualifier\n        Determines the source data elements in the message which forms the\n        basis for 6066 Control value.\n        type: an\n        maxlen: 3\n        required: true\n    [1] 1\n        id: 6066 - controlValue\n        Value obtained from summing the values specified by the Control\n        Qualifier throughout the message (Hash total).\n        type: n\n        maxlen: 18\n        required: true\n\nCNT+16:1'\nUNT - MessageTrailer http://www.unece.org/trade/untdid/d95b/trsd/trsdunt.htm\n  (MessageTrailer)\n  [0] 12\n      9900 - segmentsNumber\n      segmentsNumber\n  [1] 141260500001\n      9901 - msgRefNumber\n      msgRefNumber\n\nUNT+12+141260500001'\nUNZ - InterchangeTrailer http://www.unece.org/trade/untdid/d95b/trsd/trsdunz.htm\n  (InterchangeTrailer)\n  [0] 1\n      9902 - interchangeControlCount\n      interchangeControlCount\n  [1] 1412605\n      9903 - interchangeControlRef\n      interchangeControlRef\n```\n\nEDI\\Reader\n------------------\nRead specific segment element values from parsed EDI file.\nPass the reader a parser with a message already loaded. \n\n**INPUT**\n```php\n$p = new EDI\\Parser();\n$p-\u003eload($x);\n$r = new EDI\\Reader($p);\n$sender = $r-\u003ereadEdiDataValue('UNB', 2);\n$Dt = $r-\u003ereadUNBDateTimeOfPreparation();\n\n```\nSee section about EDI\\Parser above on how to load a file into a parser.\n\n**OUTPUT**\n\nErrors\n```php\n$r-\u003eerrors();\n```\nArray\n```php\n$r-\u003egetParsedFile();\n```\n\nEDI\\Interpreter\n---------------\nOrganizes the data parsed by EDI/Parser using the XML description of the message and the XML segments.\n\n**INPUT**\n```php\n$p = new EDI\\Parser();\n$p-\u003eload($edifile);\n$edi = $p-\u003eget();\n\n$mapping = new EDI\\Mapping\\MappingProvider('D95B');\n\n$analyser = new EDI\\Analyser();\n$segs = $analyser-\u003eloadSegmentsXml($mapping-\u003egetSegments());\n$svc = $analyser-\u003eloadSegmentsXml($mapping-\u003egetServiceSegments(3));\n\n$interpreter = new EDI\\Interpreter($mapping-\u003egetMessage('CODECO'), $segs, $svc);\n$prep = $interpreter-\u003eprepare($edi);\n```\n\n**OUTPUT**\n\nJSON\n```php\n$interpreter-\u003egetJson()\n```\n\nJSON for interchange service segments (UNB / UNZ)\n```php\n$interpreter-\u003egetJsonServiceSegments()\n```\n\nErrors (per message)\n```php\n$interpreter-\u003egetErrors()\n```\n\nExample\n-------\n\n**Edifact**\n\n`DTM+7:201309200717:203'`\n\n**Array**\n```php\n['DTM',['7','201309200717','203']]\n```\n\nTesting\n-------\nThe package should be required with composer, alongside edifact-mapping. The tests then can be run simply with phpunit in the root of the package.\n\nNotes\n------\nValid characters are: A-Za-z0-9.,-()/'+:=?!\"%\u0026*;\u003c\u003e [UNECE](http://www.unece.org/trade/untdid/texts/d422_d.htm#p5.1)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-edifact%2Fedifact","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-edifact%2Fedifact","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-edifact%2Fedifact/lists"}