Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP - Read File - Don't strip characters

Posted on 2013-02-04
4
Medium Priority
?
306 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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 84

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

688 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