Forum Moderators: coopster
<![CDATA[JVBERi0xLjMKJeTjz9IKMSAwIG9iago8PC
9UeXBlIC9QYWdlcyAKL0NvdW50IDYgCi9LaWRzIFs0IDAgUiAKMTEgMCBSIAoxNSAwIFIgCjE5IDAgUiAKMjMgMCBSIAoyNyAwIFIgCl0KPj5l.....
RkUzNzNBOTgxQTREMj48M0Q1N0NDMDFFRTg0ODhBOUYzRTMxNEMwNUFDQ0I1OTg+XQo+PgpzdGFydHhyZWYKMTE2MzMKJSVFT0YK ]]>
here's what I've been trying so far
$fp5 = fopen("Receive.xml", "rb");
$theSize = filesize("Receive.xml");
$data = fread($fp5, $theSize);
$TheData = preg_match_all("/<!\[\CDATA\[(.*?)\]\]>/", $data, $string);
print_r($string);
I'm getting nothing at all just empty array. Any suggestions? I'm on php 4.4.4 so some of the newer methods aren't available to me.
<?php
$data = "<![CDATA[JVBERi0xLjMKJeTjz9IKMSAwIG9iago8PC
9UeXBlIC9QYWdlcyAKL0NvdW50IDYgCi9LaWRzIFs0IDAgUiAKMTEgMCBSIAoxNSAwIFIgCjE5IDAgUiAKMjMgMCBSIAoyNyAwIFIgCl0KPj5l.....
RkUzNzNBOTgxQTREMj48M0Q1N0NDMDFFRTg0ODhBOUYzRTMxNEMwNUFDQ0I1OTg+XQo+PgpzdGFydHhyZWYKMTE2MzMKJSVFT0YK ]]>";
//echo $data."<pre>";
$b=explode("CDATA[",$data);
echo "<pre>"; print_r($b);
$rep = array(" ","]",">");
echo str_replace($rep,"",$b[1]);
?>
but at the same time, I strong recommend you to use some ready made PHP class, if you cannot write one, from websites like phpclasses.org to parse your xml in a more organized method. You can also use simpleXML() with PHP5.
$TheData = preg_match_all("/<!\[\CDATA\[(.*?)\]\]>/", $data, $string);
I tried
$TheData = preg_match_all("/<!\[CDATA\[(.*?)\]\]>/s", $data, $string);
print_r($string);
I got the data out of the cdata tag but each line in the xml file is on a separate line in the variable, which when trying to use the base64_decode( $string ), it doesn't properly create the pdf file due to the line spacing in the variable, how can I get the lines to run together on one continuous line?
$input = str_replace('\n', '', $input);
$TheData = preg_match_all("/<!\[CDATA\[(.*?)\]\]>/s", $data, $string);
$testing = $string[1][0];
$testing = str_replace('\n', '', $testing);
echo $testing;
Still getting the multiline text file have tried many variations of '\n', '\r\n', '\r', etc, still no luck
$TheData = preg_match_all("/<!\[CDATA\[(.*?)\]\]>/s", $data, $string);
$testing = $string[1][0];
$testing = str_replace(array("\r", "\n", "\t", " "), "", $testing);
echo $testing;
$filename = "test.pdf";
/* encode & write data (binary) */
$ifp = fopen($filename, "wb" );
fwrite( $ifp, base64_decode( $testing ) );
fclose( $ifp );