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
Related
I want to convert the content of a php file (this file is generated using some query from mysql database along with some image)to html file in order to create a pdf format. I tried converting php file to pdf but could not be succeeded. Kindly help with very short example as I am very new to the area.Thanks in advance.
you can generate a static html file from a url (to the php page) like so:
file_put_contents('static.html', file_get_contents('http://example.com/dynamic.php'));
Though writing the file to disk is probably unnecessary.
Probably your pdf function takes an html sting, in which case include and output buffering might be a suitable solution:
ob_start();
include 'dynamic.php';
$html = ob_get_clean();
create_pdf('mypdf.php', $html);
For a more specific example you would need to show your current code
I'm extracting data from MySQL into flash. First I use PHP to query the DB, and then I echo the results.
$sql = "SELECT path FROM video WHERE id = 52";
$resource = mysqli_query($conn,$sql);
$row = mysqli_fetch_assoc($resource);
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<video>\n";
echo "<path>" . $row['path'] . "</path>\n";
echo "</video>\n";
I only have one root element, and I don't see anything wrong with my markup following the root element...but then again I'm wrong and I'm sure there is an error.
--- Changed my Title so I added the error message here ---
TypeError: Error #1088: The markup in the document following the root element must be well-formed.
------EDITED ------
The value of $row['path'] is a string from my DB. I know it's valid because I deleted all xml tags and echoed $row['path'] which is the url path for the video. I also used gettype(), and it outputs a string.
When I open this file into my browser, I actually don't see anything. It's a blank page, but it's because the browser is rendering it as html elements, so I don't think that's the problem. But when I view source, I get this
<?xml version="1.0" encoding="UTF-8"?>
<video>
<path>1.mp4</path>
</video>
In addition, I created a random file with an xml extension with the xml contents above, (copied it form View Source that my php file outputs) and it works fine. I see the contents in Flash. What could be wrong with echoing it out in a php file? I'm using textWrangler. It might have something to do with BOM, any suggestions?
----EDIT NUMBER TWO ---
Here's my actionscript code. I'm still new so I didn't put it in a class but inside the first frame in my actions layer. I'm just trying to get the basics to work.
var theXML:XML;
var xmlReq:URLRequest = new URLRequest("../folderExample/poop.php");
var xmlLoader:URLLoader = new URLLoader();
function xmlLoaded(event:Event):void{
theXML = new XML(xmlLoader.data); // The Error occurs here.
trace(theXML.toXMLString());
}
xmlLoader.load(xmlReq);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
From http://www.flashdevelop.org/community/viewtopic.php?f=13&t=3128
For well-formed XML returning
TypeError: Error #1088: The markup in the document following the root element must be well-formed,
often the problem is the BOM.
Actionscript XML does not strip the BOM (Byte Order Mark) from incoming text. The BOM is an invisible character (#65279) created at the beginning of a ASP or php "echo" string, as well as some text editors, to indicate the byte-ordering of multibyte text.
You can confirm if your string has this BOM character like this:
trace( sXMLString.charCodeAt( 0 ) ); //outputs 65279
The quick solution is
sXMLString= sXMLString.replace( String.fromCharCode(65279), "" ) ;
myXML = new XML(sXMLString);
See also:
Reading php generated XML in flash?
How to load PHP dynamically generated XML in FLASH
If you don't have it already, from the second link above, try adding:
header("Content-Type: text/xml");
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;
I want to be able to create a XML File, add nodes and such to it, then output it to the screen without saving.
$bookxml = new DOMDocument('1.0', 'utf-8');
is how i have the XML file created, however i just can't anyway to display the XML file on the screen without saving it.
However i am having a problem with outputting even in save, this is the line i have
echo $bookxml->save("testing.xml");
All this does is return the file size of the newly created XML, and not the contents.
Any help would be awesome, i'm completely stumped on this.
What you're looking for is saveXML, additionally you can use htmlspecialchars to encode the xml so you can see it in your browser display.
echo htmlspecialchars($bookxml->saveXML());
You want the saveXML method, not the save method:
http://us3.php.net/manual/en/domdocument.savexml.php
I have an RTF file that I want to display inside a web page after tags have been replaced with user input.
I would like to be able to display the RTF file without having to convert it to something before displaying it.
Every time I try it now it gives me the popup open/save box even though I am telling it to display it inline with:
header("Content-type: application/msword");
header("Content-Disposition: inline; filename=mark.rtf");
header("Content-length: " . strlen($output));
echo $output;
Most browsers won't reliably display RTF content. It IS possible to parse the RTF into HTML, and display the HTML content on your web page however.
You need some kind of program to parse RTF and convert it to HTML. I'm assuming it has to be free. I do not know of any reliable free RTF parsing or RTF to HTML libraries in PHP.
I recommend you use a command-line conversion program like RTF2HTML: http://sageshome.net/?w=downloads/soft/RTF2HTML.html
You would need to download and install this program on your webserver, allow the user to upload the file to a temp directory, and then call the command line application from PHP with shell_exec():
$html_output_path = '/path/for/processing/files/'
$html_output_filename = $username . $timestamp;
if (is_uploaded_file($_FILES['userfile']['tmp_name'])
{
shell_exec('rtf2html ' .
escapeshellarg($_FILES['userfile']['tmp_name']) . " " .
$html_output_path . $html_output_filename);
}
$html_to_display = file_get_contents($html_output_path .
$html_output_filename);
Then, parse the results as HTML and display them. Not a bad strategy. Note that you will probably need to remove the head, body and possibly other tags if you're going to display the content inside another web page.
You might want to check out https://github.com/tbluemel/rtf.js for client-side RTF rendering. It's still in its early stages but it renders even embedded graphics. Support for rendering embedded WMF artwork is still very very limited, though, and requires browser support for the tag.
You needed an RTF to HTML converter written in PHP. I think this page contains your solution:
http://www.websofia.com/2014/05/a-working-rtf-to-html-converter-in-php/
First: you've got your content-type wrong. for RTF it's text/rtf
Second: you'll only be able to display in-line this type of content, which can be rendered by the web browser. RTF is not one of these. So you won't be able to display it in-line without converting it, or without some plug-in for the browser. Of course conversion might be on-the-fly.
Web pages can only contain HTML. You would need a browser plugin like flash to display other file types. See Scribd for example.
This isn't exactly an answer to your question, but one thing you may want to do is remove the "filename=mark.rtf" from the header. I've had browsers treat something as a download if I include "filename" in the header, even if the "Content-Disposition" is "inline".
You can't just output a file from within PHP code. You need to extract the data from it, then print the contents inline.
The php function 'file_get_contents' may do what you need. The functions manual is here: http://us2.php.net/filegetcontents
A sample usage is here:
$contents = file_get_contents('yourfile.rtf');