What language or format is this in? - php

After looking at the Wordpress and Joomla database, I began to recognize strings in this format. What is it, how does it work?
here's an example:
a:5:{s:13:"administrator";a:2:{s:4:"name";s:13:"Administrator";s:12:"capabilities";a:62:{s:13:"switch_themes";b:1;s:11:"edit_themes";b:1;

that was serialized string from an object or array.

It's a serialized array. Basically a string to be used by the serialize() and unserialize() functions in PHP, the base language for wordpress and likely joomla though I have never worked with joomla myself.

Related

What is the name of the format used by Wordpress to store user settings?

I have searched for a while now and can't seem to find the right answer. Maybe I don't know what to search. What is the name of the format used on this string: a:1:{i:313;i:1;} and what is a good PHP parser for it?
It's PHP built-in function serialize().
To parse it use unserialize().

Is there a XML decoder for PHP objects?

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.

How to dynamically translate a webpage [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How would you transform a pre-existing web app in a multilingual one?
Best way to internationalize simple PHP website
I'm trying to figure out how to translate all the static texts on my webpage (I'm using PHP). But I'm not really sure what the "correct" way is. This is what I thought of so far, but maybe it's all wrong :D
1.
For every static piece of text on the page, just get the translation with something like "getTranslation("Hello World!") and it will just look up the translation in the database or a file like XML/CSV/PHP with all the translations.
But this seem pretty bad since we will have to query the database or parse the file on every page, everytime it's refreshed/loaded.
2
Everytime a page is loaded I could read from the database/file and store the translations for the current language in an array and get the translations from the array as the page is building, instead querying the database / parsing the file again.
3
Is there some way to read the translations only once and then make it accesible for all pages? The only thing I can think of is php's SESSION but it just seems so wrong to store the translations there.
So what the "most common" or "right" way to do it?
Happy hunting!
Sounds like you need gettext. gettext is widely used and widely supported. I'm pretty sure it's also pretty well optimized.

Auto extract strings to defines

I just inherited a website written in PHP to internationalize it... The problem is the code is not consistent. It has some functions that have strings inside echo and another pieces and in another functions the php is closed and html is presented the right way.
I was looking for a tool that could easy my job as much as possible. Retrieving as much strings as it could and defining (through defines) in another file.
I though about creating a script with regex functions to achieve this but if there was anything out there... I looked but couldn't find. Maybe I'm using wrong terms as I'm not English native.
Does anyone know a good way to do this?
If you are open to using gettext for I18N, then you can use xgettext: http://www.gnu.org/s/hello/manual/gettext/xgettext-Invocation.html
Here is a tutorial detailing how you can use it in PHP: http://www.phpdig.net/ref/rn26.html

Parsing Drupal String

I am writing my own drupal website side API.
I see that some tables containg some odd strings that i need to pharse, I cant fine any logic in it.
for example, I have upload via the admin a file and i have found the relevant row with the data.
a:12:{s:3:"alt";s:10:"aaaaaaaaaa";s:3:"fid";s:2:"22";s:5:"width";i:1024;s:6:"height";i:680;s:8:"duration";i:0;s:12:"audio_format";s:0:"";s:17:"audio_sample_rate";i:0;s:18:"audio_channel_mode";s:0:"";s:13:"audio_bitrate";i:0;s:18:"audio_bitrate_mode";s:0:"";s:4:"tags";a:0:{}s:5:"title";s:0:"";}
I need to pharse out the aaaaaaaaaa string which is the image "alt".
Do you have an idea of how to parse this string, I hope that your rule will be soutable for drupa odd strings in general?
Thanks
These strings are not Drupal-specific. They are serialized PHP data types (objects, arrays, etc.). See the PHP manual for serialize().
The string you've quoted is a PHP serialized array. See the PHP manual page for the serialize() and unserialize() functions for more info.
However I strongly doubt that you actually need to be delving into the data in this way. That data will have been set up in Drupal, and can be modified in Drupal. I can't say where, since the data you've provided is lacking context, but it'll likely be somewhere in your administration area.
I'd suggest you find where it's configured and change it there. Hacking around directly with the serialized strings that Drupal creates is a sure-fire way to damage your Drupal installation if you don't know what you're doing.
That string is serialised. You can unserialize it using http://php.net/manual/en/function.unserialize.php

Categories