I am build a application in Delphi that stores some configuration that is not going to be passive to query filters on the database. So I decided to create some blob text fields to store those configurations that will only be used as keys to configure some modules of the application.
In this Delphi side of the application, I am using NativeXML run-time components to decode the configuration class or record type of each module into/from XML and populate that field on the database.
My problem came when I realized that this application will have a web site module where people will register for clinical attending and this part will need to use some of the configuration stored on that XML on the database. So...
I am newbie on PHP and I wish to know from you if PHP has the ability to do that XML<->Object\Record DeCoding or do I have to look for a library that makes it possible?
Note: If there is only a record type capacity, I will use it, but if not, I prefer to use classes
Edit:
In response to some comments on answers, I would say that I use XML instead of JSON because of this Delphi XML library that suited me well! If someone could point me to a goo JSON DeCode library to convert JSON<->Delphi Objects will really use it instead of XML because I like to work with JSON. Would that solve the problem on the PHP parsing?
That is not that easy in PHP. However there are lots of smart folks out there, who where facing the same problem.
Paul Ferrertt has a XML-Encode Class here:
http://www.paulferrett.com/2009/encoding-an-object-in-xml-with-php/
In PHP there are multiple functions to decode a XML sheet. Start here:
http://www.php.net/manual/en/refs.xml.php
http://php.net/manual/en/function.xml-parse.php
However you won' t be able to get an object back as easy as with json_decode() and that for a reason XML is not meant to transfer objects (and the like) around. You have to write your own conversion methods.
I suggest you to read this : http://www.php.net/manual/en/refs.xml.php. Some of these libraries are easier to use that are others, some others are more powerful, etc.
Related
I deal with serialized PHP data a lot (wp developer) and I'd like to know if anyone out there has figured out how to beautify serialized php data from within ST3. I'd like to be able to view my serialized php data in a nice indented format in the same way that I can already view my JSON and other serialized data formats. There are plenty of tools online that do this, but i'd like on integrated into ST3.
There is a PHP beautifier out there which i believe runs the PHP_Beautifier PEAR package, but it does nothing to serialized data (probably because the extra whitespace would break the format).
I have had relative luck with copying the data to a new file and running a regex replace /(.*?);(.*?);/$1 : $2,/ and then running Format as Javascript from CodeFormatter. but obviously this quite a bit of work to do each time.
I'm new to ST3 so I'd like some opinions on what my best option is here. Is there a solution out there or should I create a plugin to send the string to an online beautifier, or write a macro or something?
Cheers
I am afraid that PHP serialized data cannot be formatted (like JSON or XML)
The PHP serialization format does not allow additional white-space between the serialization token. The only thing you can do is to unserialize the data for display and then re-serialize it before saving the file.
I am trying to write a web service API using PHP and the Yii framework. This means that I will be using SOAP web services, since Yii does not directly support RESTful web services.
I would like to return results in XML format, as strings (this might be stupid, but I'm working with rather cumbersome data types that would make life more difficult for the web service clients trying to use them). The problem I'm facing is that the XML I'm returning contains tags, which leads to the strings not being read properly by the web service client.
For instance, I can return this string in one of my web services:
"hello"
But not this string:
"<hello>"
(An empty string is read by the client)
So, is there a way for a SOAP web service to return an XML document as a string (in general, or using Yii in particular)?
This should really be done by the framework (don't know about Yii though), but since it doesn't seem to work automatically for you, try escaping the data first:
$data_to_send = htmlspecialchars($data_to_send);
If Yii doesn't encode the data, your client will see the correct output (the raw XML string) when fetching the data from their SOAP library. If Yii, however, does encode the data, it will get double-encoded which is probably not what you want, but if it does encode it you shouldn't have this problem in the first place...
If your data contains characters that are also XML tags, you can use the CDATA option.
<value><![CDATA[<hello>]]></value>
Please don't use soap. It is one if the worst technologies ever made (see the numerous posts on SO) . Yii does support REST now (fully as of 1.17). Just use JSON format. Do you need to delete or insert from the client?
I wanted to know if this is possible?
I would like to create a cross platform Flash projector and files and than create an ISO from it for the user to download.
Google did not help me much so far...
Of course it is possible to do directly from PHP.
However, as one of the comments to your question states, it's probably going to be easier to call an external binary to do the work for you (Although not all hosts may have mkisofs installed).
If you really must do this from PHP, here's some useful references for you.
ISO 9660 specification (ECMA-119) - This is the file format for "ISO" image files.
PHP pack() and unpack() - These will help you manipulate binary data in PHP.
Once you're familiar with the file structure, you may be able to create some pre-compiled segments, and just patch them at various offsets as well as inserting the payload.
Good luck!
Is there a native PHP wbxml API that can be used platform-independently? Perhaps a loadable module?
I have seen the pecl implementations but I have not been able to successfully work with the builds on win32 platforms.
I am not an expert, but what I found out there numbered two options, essentially.
One, the pecl library that you are having trouble with.
Two, I found WBXML encoder and decoder classes in Horde of all places. They might give you a starting point, and since they are open source, they might meet your needs quite nicely. Here is a link where I found them.
http://phpxref.com/xref/horde/lib/XML/WBXML/index.html
I don't know a huge amount about WBXML, but from what I can gather it's a binary-formatted XML file. I suppose at the simplest you could use the XML modules such as simpleXML to generate your XML document, output it as a string and then use PHP's built in file handling functions (fopen, fwrite, etc) to dump the string as binary data to a file. To reverse the process load the file as a string and have SimpleXML parse it.
However, without knowing the specific details of the WBXML format, I'm sure there's more to it tan that. You'd also have to implement the necessary code yourself, but as you could implement it in PHP itself that should make cross-platform portability a bit simpler to accomplish.
Not really an answer as such, I'm afraid, but I hope it gets you going in the right direction.
I have been making HTML/PHP/MySQL database apps for quite a while now. I have avoided using XML/XSLT in any application since I just pull the data out and format it within my PHP script, and display it.
Assuming I am not wanting my data to be portable to other people's applications (via XML), is there any reason to implement an XML/XSLT based web app or is it a matter of preference?
Thanks.
I use XML/XSLT as a template engine.
Througout my script, I gather my data as nodes and put them in an XML object. When I need to display data, I feed this XML object to an XSLT and display the result.
It is a matter of preference.
XML/XSLT are useful when transforming XML to multiple other XML formats (rss, xhtml etc...), so if you don't need this kind of functionality, don't go with it.
They also add a cost in complexity and processing power. Again, if you don't need it, don't use them.