Solved

PHP - Read File - Don't strip characters

Posted on 2013-02-04
4
303 Views
Last Modified: 2013-02-09
I have an EDI file with the following typical data that I'm trying to read using php:

<TRANSACTION SET PURPOSE CODE>,00, Original
<PURCHASE ORDER TYPE CODE>,NE
<PURCHASE ORDER NUMBER>,19191987
<PURCHASE ORDER DATE>,01/15/2013

No matter what type of file open or read I use, the data is read with the <> characters & all characters between the <> characters removed:

,00, Original
,NE
,19191987
,01/15/2013

How can I read the original data as is?

Thank you in advance.

AielloJ
0
Comment
Question by:AielloJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 38852937
It's probably being read fine by PHP but code like that will be hidden when displayed on a web page.  Anything between <> is assumed to be a tag.  You can convert it to &lt; and &gt; with htmlentities so it will display on a page.  If you look at the view source for this page, you will see that's exactly what they are doing to get it to display here.

http://www.php.net/manual/en/function.htmlentities.php
0
 
LVL 13

Author Comment

by:AielloJ
ID: 38853419
Dave,

Is the original characters what's "really" in the string.  I don't need to display it, just be able to parse out the tags so I can extract the data elements.  If the original strings are intact, then I can just do string operations on them.  The thing that made me think they were being filtered on the read ooperation, is that NetBeans is showing the variables filtered.

Best regards,

AielloJ
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38853886
I don't know about Netbeans, never used it.  Look at it in a browser.  The tags will be there in the "View Source" .
0
 
LVL 1

Expert Comment

by:Shaun_King_23
ID: 38854216
Hi AielloJ,

This is how i would do it:

xml format.

<AielloJ>
	<Transactions>
		<Transaction>
			<TRANSACTION_SET_PURPOSE_CODE>,00, Original</TRANSACTION_SET_PURPOSE_CODE>
			<PURCHASE_ORDER_TYPE_CODE>,NE</PURCHASE_ORDER_TYPE_CODE>
			<PURCHASE_ORDER_NUMBER>,19191987</PURCHASE_ORDER_NUMBER>
			<PURCHASE_ORDER_DATE>,01/15/2013</PURCHASE_ORDER_DATE>
		</Transaction>
	</Transactions>
</AielloJ>

Open in new window


php to parse the data:

<?php

$file = ('file.xml');
$contents = file_get_contents($file);

/*********************************************
create SimpleXML object from string for easier parsing 
*********************************************/
				
$XmlObj = simplexml_load_String($contents);

$xmlItems = $XmlObj->Transactions->Transaction;

if(empty($xmlItems)){
		echo "No Transactions to Process";
}else{
	echo "Processing Transactions";
	foreach($xmlItems as $xmlItem) {
		echo $xmlItem->TRANSACTION_SET_PURPOSE_CODE;
		echo $xmlItem->PURCHASE_ORDER_TYPE_CODE;
		echo $xmlItem->PURCHASE_ORDER_NUMBER;
		echo $xmlItem->PURCHASE_ORDER_DATE;
	}
}

?>

Open in new window


Hope this helps.

Many Thanks

Shaun
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question