php xml SimpleXMLElement addChild big data breaking xml - php

I am trying to insert base64_encoded pdf content in xml with below code.
1) Getting pdf data in variable.
$varFilePath = 'temp_invoices/' . $varFileName;
$arrFileData = file_get_contents($varFilePath);
$varPdfBase64 = base64_encode($arrFileData);
2) Using base64 data in xml tag
$Attachment->addChild('Attachment', $varPdfBase64);
The variable $varPdfBase64 has too big content and its creating problem.
Now when I am trying to download xml file this is showing plain text instead downloading with xml tags.
Note:- All tags are present in source code(ctrl+u).
How can I resolve this issue?

Related

Load xml gzipped from external link

I need to load a gzipped xml from an external link but I don't know how to do it.
Now I'm loading this xml file to my server and then I change every 3 days the xml adress in the variable.
The code I'm using now for loading xml is this:
$xmlFile= new SimpleXMLElement('xml/abcd_201407281213_12074_28203833.xml', 0, true);
The link gived to me to download the xml file from their server is like this:
http://nameofthewebsite.com/folder/28203833C78648187.xml?ticket=BA57F0D9FF910FE4DB517F4EC1A275A2&gZipCompress=yes
Someone can help me please?

Getting data from an SVG file using PHP

I'm not sure if this is a duplicate question or not but I'll ask it anyway.
How do I take image data from an SVG file and pass it into PHP, then output the info with HTML? I know it can be done in Javascript, but that's not how this particular project needs to be done.
you can use file_get_contents to read svg file data in php.
$templateString= array(
'front' => file_get_contents($svgUrl, FILE_USE_INCLUDE_PATH)
);
echo $templateString;
Now complete svg data is in $templateString variable.
This is what I did and got my SVG XML content from URL.
$svg_file = file_get_contents($url);
echo $svg_file;

How to Download XML File from a web service with HTML like code

I am new to PHP. I am downloading an XML file from a web service using PHP. I can download the file using this code:
$sourcefile = "http...com?querystring=string";
$destinationfile = 'data\description.xml';
$xml = file_get_contents($sourcefile);
file_put_contents($destinationfile, $xml);
But when I open the XML file, it has < where < should be and > where > should be.
I added this line of code to decode it before saving it to file, which fixes the above problem:
$xml = html_entity_decode($xml);
This doesn't seem to me to be the right way to go about it. Also, I am getting a weird piece of text showing up in the XML file, which prevents me from parsing the XML file:

I tried using str_replace($xml) right before decoding it (and tried it after decoding it), but that wouldn't get rid of it.
What is the correct way to download an XML file using GET from a web service in PHP and will it get rid of that weird string ()?

Parse JSON from webpage

I made a php script which connects to my database and parse in JSON format some news. My problem is that the content of the news are in HTML format - with <br> , <img> and so on(so when I open the script - ex: http://localhost/android_connect/get_news.php the browser interprets the HTML tags as it was designed to) .
Is there anyway to parse from JSON the
view-source:http://localhost/android_connect/get_news.php
webpage?
You can read the source of the HTML page with file_get_contents().
$json_news = file_get_contents ("http://localhost/android_connect/get_news.php");
echo $json_news;

convert html characters back to text in Flash - AS3

I need to generate an editable xml file to supply content to a flash website.
I am generating my file with a html form, and htmlspecialchars e.g.:
$currentItem = htmlspecialchars(stripslashes($currentItem));
This is to prevent xml entries which would produce the error "XML Parsing Error: not well-formed", such as
<entry title="Words & Things">
---------------------^
It has the side effect of making the flash file display the html codes for the content, rather than the proper characters.
Is there a good way to convert the codes back, once they are read into the Flash file (as3)?
Maybe try:
public function htmlUnescape(str:String):String
{
return new XMLDocument(str).firstChild.nodeValue;
}
(Found at: http://www.razorberry.com/blog/archives/2007/11/02/converting-html-entities-in-as3/)
Use html_entity_decode: http://us.php.net/manual/en/function.html-entity-decode.php

Categories