Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Domxml_new_doc - Can I Add Encoding Attribute?


I've got a question about adding encoding attribute to my DOM XML Document?

I'm from Poland and we use extended latin alphabet - I'd like to use
iso-8859-2 Polish charset

e.g.:
<?xml version="1.0" encoding="iso-8859-2"?>

is there such posibility in DOM XML?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Find Out Encoding Of A File With Php, And Convert It To UTF-8 Encoding
In my script I need to find out the encoding of a file and in case it
is not of the kind UTF-8 I need to convert it to that format.

XML - Sorting By Attribute
I'm not sure whether this is a question about php or xml or what to be honest - a poke in the right direction would be much appreciated...

I'm storing news articles in XML format.

newsitems.php which contains the XML looks like this; ....

LDAP And TelephoneNumber Attribute
Anyone have a problem with PHP returning the telephoneNumber attribute empty while all the other attributes return just fine. Someone had the same exact problem on phpbuilder but it was never solved. Apparently it holds true for facsimileTelephoneNumber also. Any ideas?

A '<' Character Cannot Be Used In Attribute 'href', Except Through <[xml]
The following embedded snip it of PHP code won't validate using xhtml 1.0 strict. When validating I get the following error:

A '<' character cannot be used in attribute 'href', except through <[xml] Code:

href="/_Director/forms.php? <?PHP create_request_query('AskQuestions', 'AskQuestions'); ?>" Any idea what's wrong?

Populating An Auto_increament Attribute
I have just designed a BD. there are companies with auto increament which are integer. When I try to populate it after i tool value from another form and try to insert it into a table i recieve an error! I don't ask the companyID value from user as it is auto increament. Don't tell me to put NULL for that entry as it didn't work as well! Code:

SimpleXML Parsing By Attribute Value
I have an existing XML data set and would like to parse it with PHP5 based on the value of an attribute (any attribute!). I don't want to convert all my data from an attribute-heavy structure to a more proper element-based structure if I don't have to because of the javascript I am using on the client side. Listed below is the XML structure and PHP code I have been testing.

My existing data structure looks like this:
<gallery>
<photos>
<photo
path = "sunflower01.jpg"
width = "500"
height = "375"
thumbpath = "sunflower01.jpg"
thumbwidth = "125"
thumbheight = "94">
</photo>
</photos>
</gallery>

The script is here:

<?php
$xml = simplexml_load_file("pictures.xml");
$image = $xml->xpath("/gallery/photos/photo[@path='sunflower01.jpg']");
echo $image[0]->photo@thumbpath;
?>

Counting Items In An Array Having X Attribute
I want to randomly select 5 cards from a standard playing card deck and count how many of each suit are returned:

[connect]
$sql = "SELECT * FROM cards ORDER BY RAND()LIMIT 5";
$result = mysql_query($sql);
while($cards = mysql_fetch_array($result)) {

$value = $cards["card_value"];
$suit = $cards["card_suit"];
$image = $cards["card_image"];
--------

Using count() within the loop returns a count of 1 since each card can only be of one suit. I tried using something like this:

$spades = 0;
if($suit='spades') {
$spades = $spades+1;
}

and I tried a foreach statement to count within the loop which always returns a count of 1.

Would someone be so kind as to point me in the right direction?

Sort A Group Of Nodes By Attribute? How?
I have the following XML file:

<?xml version="1.0" encoding="iso-8859-1"?>
<items>
<item line="2">all that glitters is gold,</item>
<item line="1">Theres a lady thats sure,</item>
<item line="3">and she's buying a stairway to heaven</item>
</items>

To output this code Im using the following PHP:

$xmldoc = domxml_open_file('stairway.xml',
DOMXML_LOAD_DONT_KEEP_BLANKS);
$node = $xmldoc->document_element();
if ($xmldoc->has_child_nodes()) {
$node = $node->first_child();
$endwhile = false;
while ($endwhile != true) {
echo $node->get_content() . "<br />";
if ($node->next_sibling()) {
$node = $node->next_sibling();
}else{
$endwhile = true;
}
}
}

This does what it supposed to do except I want to ensure that it
outputs nodes ordered by 'line' attribute. The obvious answer would be
to put them in order in the XML file and the above example is very
simple so that you get the point, the real life example however will be
much larger and encase anyone put something in the wrong order it would
muck up my presentation. How could I adapt my code above to allow my
nodes to be sorted? I dont mind the nodes being out of order in the
physical file (stairway.xml) but when they are output using my script,
I want them to be ordered.

Accept Form Attribute Not Working
I cannot get my accept attribute working properly inside either my form, or my input tag. W3schools says that accept is supposed to go inside the input tag, but msdn says it goes in the form tag. I need it for an upload form I'm making, I want to only allow application/octet-stream type files, so I put this as my opening form tag:

<form enctype="multipart/form-data" accept="application/octet-stream" action="{$_SERVER['PHP_SELF']}" method="POST">

But I can still upload music, text files, and movies.  What gives?

After I Load An XML File, Can I Sort It By Node Attribute
After loading an xml file, is it possible to sort it by attribute?

For example, I have the following xml file:

<xml...
<diary>
<entry date="2005-01-01">I went to the park</entry>
<entry date="2005-01-03">Sold the car today</entry>
<entry date="2005-01-02">Went for a stroll</entry>
</diary>

When I go to load this using PHP, I would use some this similar to
this:

$xmldoc = domxml_open_file('diary.xml', DOMXML_LOAD_DONT_KEEP_BLANKS);

$node = $xmldoc->document_element();

Before I go storming through the xml tree outputing along the way, can
I sort it by (in this case) date?

Php-4.4.0 And Test.wsf = Error: The Value For The Attribute Is Not Valid: Language
We need to use version php-4.4.0-Win32 because one of the portal software
doesn't support version php-5.0.5-Win32. We cannot get the PHP setup part
working. Here is the error message:

Windows Script Host

Script: C:kits est.wsf
Line: 3
Char: 11
Error: The value for the attribute is not valid: language
Code: 80040049
Source: Windows Script Host

Here is the code from the install.txt

To test if ActiveScript is working, create a new file, named test.wsf (the
extension is very important) and type:

<job id="test">

<script language="PHPScript">
$WScript->Echo("Hello World!");
</script>

</job>

Save and double-click on the file. If you receive a little window saying
"Hello World!" you're done.

Everything works fine using php-5.0.5-Win32.

Simplexml And Attributes With A Namespace In Front. How Do You Getthe Attribute?
Here's a bit of xml code that works.

<?php

$string =
"<?xml version="1.0" standalone="yes"?>
<world>
<people xmlns:ss="http://crap">
<person id="5">John Doe</person>
<person id="2">Susie Q. Public</person>
</people>
</world>";

$xml = simplexml_load_string($string);
print "<pre>";
print_r($xml);
print "</pre>";

foreach($xml->people->person as $p)
foreach($p->attributes() as $a =$b)
{
print "$a =$b<br />";
}

// prints out
// id =5
// id =2
?>

Now what if I change the first person to this
<person ss:id="5">John Doe</person>

Anyone know how to get the id?

This is a question that is pertinent to an excel .xml file as
you'll get lines like this
<Cell ss:Index="3">stuff</Cell>

btw: there is a guide on ibm that tells you how to do this with php
and dom. I'm just wondering if there's a way to do it with simplexml.

URL Encoding
In one of my PHP applications, I generate a dynamic link to another page. The parameter list contains a few variables with some special characters, so as expected, I use urlencode() to encode the parameters before plopping them into the URL.

For some strange reason, the link doesn't work - I get a "page cannot be displayed" error in IE 6. NS 6 starts to load it, then just stops. Oddly enough, if I go into the location bar (under IE at least), and delete one (1) character, any character from this one particular parameter (search_expr), the page loads fine (albeit with a messed up parameter). Code:

URL Encoding
Can anyone point me in the direction of a tutorial on URL encoding? I am creating a website and i want to use 1 page which contains the layout, then seperate pages with the content. i would do it something similar to this:

http://website.com/index.php?page=links

Then that would just call up a .inc page specified in the page= variable and display it on index.php.

Php Encoding
i was wondering, which is a good-freeware php enconding alternative?
Im running the apache server on a windows platform.

Encoding
I have a problem. How can I transform this xml:
$xml="<name>Niccol&#xF2;</name>"
to this
$xml="<name>Niccolò</name>"

I recive by CURL from a site this xml:

<?xml version="1.0">
<name>Niccol&#xF2;</name>

but, for some reasons, I want:

<?xml version="1.0">
<name>Niccolò</name>


Which Encoding?
Not really a PHP question, but i've got an app that sends me this type of
encoding:

á (&aacute;) translates to %C3%A1
ñ (&ntilde;) translates to %C3%B1

i've tried several decodings with PHP without any good result.
Anyone knows which type of encoding is this and which function to use in
order to decode it with PHP?

Encoding
my website is parsing 4 external xml files (rss feeds) and writes them in a mysql database. my problem is that 2 of the xml files are encoded in utf-8 and 2 of them are windows 1250. when i need to retrieve the data from the database and display it on my site (which is utf-8) i have a problem with special characters that are encoded in windows 1250. I need all the data in my database to be encoded in one way. how to do that ? or is there another way?

Help On Character Encoding
I have a string in windows-1256 character set. But i would like to change from this chracter set to utf-8. (actually it is for to display arabic text). I am using in my whole site utf-8.
Any help highly appreciated.

Chinese Encoding
I have a forum mainly in Chinese character. There are some characters which cannot be shown correctly and turn into "& #22175" ... does anyone know how to fix this?

Email Encoding
I'm using the code below to send emails right now. Its is secure?

Low-end PHP Encoding For Windows
FYI, BadBlue added a built-in PHP encoding capability to the enterprise version of their Windows web server. The personal edition of the server is a free download and is a quick easy way to get PHP running: http://badblue.com/helpphps.htm .

Encoding Problem
I have a dom tree representing the content of a html document. In the xml I
use &#x20AC; as the euro sign. I think I need to do this to be able to use
xsl transformations. After the xsl transformation I use a small SAX
parser. But my &#x20AC; gets converted to: â,¬50.
I've tried passing xml_parser_create() 'UTF-8' and '' (hint from php.net)
but it only makes things worse ( ? or squares are displayed ).
How do i have to encode characters to be able to pass them to SAX. Is there
a build in function or do I use str_replace()?

Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
The soul would have no rainbow had the eyes no tears.

GB2312 Encoding In PHP
I have language text stored as variables in text files, which are
'included' by my PHP scripts (is there a better way?). However, I seem
to have a problem with the simplified chinese GB2312 encoding format.

I thought that most foreign encoding mechanisms would avoid the use of
the quotation mark - however, I saved something out as GB2312 and now
effectively get parse errors (due to premature quotes which appear to
form parts of the Chinese characters themselves).

A few other websites I tested though don't seem to have a problem
sending me mail in GB2312 though ... so they must have somehow managed.

Locale And Different Encoding
I have a simple question about locale and PHP5.

I'm using polish characters but I encode them in UTF-8.
I was sorting an array with usort($array, 'strcoll'); but I've entred a
problem.
I was sorting arrays this way:

setlocale(LC_ALL, 'pl_PL.utf8');
usort($array, 'strcoll');

but it turned out to be completely wrong...

I've started to test various encodings on various OS and ended with
this sample PHP script
that sorts UTF-8 encoded array on both Linux and Windows with locale
encoding set to ISO-8859-2:

<? // file encoding is UTF-8
$array = array('Aea', 'Eaz', 'Eaz', 'Eaz', 'Aea', 'Aeas');

var_dump(mb_detect_encoding($array[1])); // shows UTF-8 - OK

// set locale encoding ISO-8859-2
// pl_PL for Linux
// polish_Poland.28592 for Windows
if (PHP_OS == 'WINNT') {
setlocale(LC_ALL, 'polish_Poland.28592');
} else {
setlocale(LC_ALL, 'pl_PL');
}

// sort
usort($array, 'strcoll');

// works OK on both Linux and Windows
var_dump($array);
?>

how come it works on both Linux Gentoo PHP 5.1.1 and
Windows NT PHP 5.1.4?

the contents of $array contents are encoded in UTF-8, but encoding is
set to ISO-8859-2 (via setlocale)

Php Script Encoding
this is my first "topic" on Google Groups.

I'm looking for a solution for 4 days, without results.

So... my apache is serving pages in UTF-8 but my php scripts are writed
(I'm speaking about strings) in ISO-8859-1.

How can I say at apache how to interpret my scripts in a different
charset?

I don't want to change every "è" with "&egrave;"
I think that it should be a simple configuration in the .conf or in the
..ini but... nothig found about.

SoapVar And Encoding
what's going on with the following (I'm working in non-WSDL mode).
Basically, I need the following in the SOAP request body:

<ns6:create>
...
<property>
<name>Property 1</name>
<value>Test Value 1</value>
</property>
<property>
<name>Property 2</name>
<value>Test Value 2</value>
</property>
</ns6:create>

So I've created a class called Create that has the required members,
and stores the property elements (which are instances of a class called
NamedValue) in an array:

class NamedValue {
public $name;
public $value;

public function __construct($name, $value) { ... }
}

class Create {
public $id;
public $parent;
public $type;
public $property;

public function __construct(...) {
...
$property = array(
new NamedValue("Property 1", "Test Value 1"),
new NamedValue("Property 2", "Test Value 2")
);
}
}

Euc-kr Encoding Problem
I have a dom tree representing the content of a html document.
I use character-set as the euc-kr sign.

Can I use a <?xml encoding="euc-kr" ?>
This source don't work.

How Can I use character-set as the euc-kr ?

Character Encoding In PHP & GD2?
I have been working on a dynamic image in GD2 which acts as a chatbox in a forum signature. It all seems to be working pretty well, but I have come across a bug (of sorts): if the user were to enter characters such as '¬_¬' the result in the image is shown as 'Ž_Ž'.

Is there any way that, using PHP, I can change this so that is actually understands the characters and would print '¬_¬'.?

Character Encoding
I'm working on a site for my brothers friend and it has a commentary system.
The commentaries get added by calling a Javascript which updates the current page and then call a PHP script to store the comment in a mySQL database.
My problem is at if the user uses any kind of special chars like the danish chars: æ, ø and å then the PHP script will just die on them. It will store the message until the chars and then stop.

I've tried running an escape () in the javascript on the txt i'm sending, and i've tried using CONVERT ('string' USING utf8) in the SQL query. The entire site is encoded in UTF-8, and so is the database but the user might type in ISO-8859-1 (?).

Somewhere else on the site i have a fileupload, here the page calls the upload script directly and it has no problems storing special chars in the database, so i'm thinking the problem might be a combination of the Javascript and PHP.

I'm hoping someone has an idea to what might be wrong. Code:

Detect Character Encoding?
My Problem is I want to build my own small web interface. works fine with imap_ functions so far. But now i got problems with Mails coming from MS Outlook - they are UTF-7 or UTF-8 encoded.

I don't know how to find out how they are encoded?

Second Problem: Got a character Sequence in the subject looking like that:

Ihre Anfrage: =?iso-8859-1?Q?minpoll=20timelimit=20wie=20gro=DF=3F?=

Don't know what to do with that.

Perhaps someone could drop some info on encoding.

Encoding/decoding A Variable
Is there a function that will temporarily encode a variable (say, for passing through a URL), and another that would decode the same?

Character Encoding Issues
I have built a CMS for a client. They client is copy pasting characters from Microsoft Word into the CMS and saving. When the CMS content is later displayed, several of the characters are shown as wier junk characters like: — or ’.

I fixed this at one level by converting the MySQL database to UTF8. This fixed it insofar as my computer is now diaplaying those characters properly but apparently some other computers are not. Some other computers are still showing wierd characters.

Does anyone know what the problem thus might still be? Are some client machines missing the fontmaps to express those characters? Or, are they not understanding to display that text as UTF8 perhaps?

SOAP And Accept-Encoding
I'm trying to make a SOAP request, and enable compression in
the response (by sending the Accept-Encoding header). To do this, I'm
sending 'compression' =SOAP_COMPRESSION_ACCEPT |
SOAP_COMPRESSION_GZIP in the SoapClient constructor's options.

But when I print the request headers, I don't see the Accept-Encoding
header. Am I doing something wrong?

I also tried SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 9 to
set the compression level, as I've seen in some examples.

I just downloaded and compiled php 5.2.1 with --enable-soap on Mac OS
10.4.9.

The full example is below:
$o_client = new SoapClient($wsdlURL, array(
'trace' =true,
'compression' =SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'login' =$login,
'password' =$password
));
$o_result = $o_client->acknowledge();
echo $o_client->__getLastRequestHeaders();

Zend Optimizer Encoding
I'm currently running into problems with Zend Optimized PHP code; or
more clear, a partner of mine asked me to adapt a script he bought which
is encoded this way.

Does anyone know if this can be done, or if there are any projects
trying to develop a free decoder/decompiler?

I know this might be a bit off-topic here, but I couldn't find a list
that seemed to fit better to me.

Send Request With Encoding
Does anyone know if it allows to send request with specific encoding?

What i want to do is sending japanese as a parameter. But always gives
me an error "Invalid protocol "

$http_request = new Snoopy;
$str = mb_convert_encoding($this -mAddress,"UTF-8", "Shift_JIS");
$url = "http://www.myusite.jp/api/?v=1.1&q='"+$str+"'";

$http_request -fetch( $url );
if( !$http_request -error ){
}

Encoding Problem, Can't Solve It
Text I get:
# stat¸ pakeitimai
# em s paskirties keitimas

As you can see some letters isn't exactly as it should be. It's in
UTF-8 in MySQL (utf8_lithuanian_ci) and I transfer using utf8
encoding. The problem I need those letters, I think those should be
called latin. But where they are gone I can't image.

Flex Form And Encoding
I have a RIA made in Flex whos send data to a PHP Script before I store the
data in a database. The function to format my data looks like this:

Character Encoding Issues
When I use utf-8 encoding my page shows up fine. However, if I use
iso-8859-1 I get some funky characters that show up at the top of my page
where I am just calling "require_once." I am using a Win32/IIS/ISAPI/PHP5
installation, anyone have an idea of what's going on and how to resolve?

Functions' Compatibility For UTF-8 Encoding
I'm writing a system with PHP which encodes with UTF-8 encoding. Everything is encoded with UTF-8 encoding.

In order to work with UTF-8 encoded strings, I need to use special functions - mbString function (stands for Multi Byte String), that specially compatible for UTF-8 encoding and others.

The problem is that there aren't enough mbString functions so that I will be able to work well with UTF-8 encoded strings. Many important mbString functions are missing.

I wrote a list of regular functions and I need to know if they can work well & suitable for UTF-8 encoded strings. Code:

Saved File Encoding
I am querying a database and saving the results as a tab-delimited file.  Is there a way to force the saved file to open in a certain encoding such as ISO Latin 1? Also, what is the best way to deal with carriage returns in the data I am saving?

Character Encoding And Rewrite?
im having a real problem with character encoding and php i aware that php has some problems with character encoding but i dont really understand them

whats got me even more stumped is that when i was developing the same thing on my pc i never had this problem im now on a mac
whats more the problem only seems to happen when using the rewrite rule in the htaccess?

basically if i have an file index.html and it is
<?php
      echo "£";
?>

it echos a £ sign fine

if however i use an htaccess file to redirect any request to another file lets say invoke.html and it has the same thing it outputs £

i know for this example i should just echo &pound;
but this isnt exactly what im trying to do
this is just the simpliest example of the problem
what im actually doing is fopen fread a file then using strpos to find any £ symbols

the £ symbols in the file are just £ symbols
if i echo the read file contents they output as just £ symbols

however if i put "£" in as the needle for strpos it goes in as £ and therefore doesnt find it in the haystack.

Encoding Necessary To Send The TM Symbol Via Mail()?
Anybody know what encoding is necessary to send text containing the TM symbol via mail()?

The html is " & t r a d e ; " or " & # 1 5 3 ; " and email source has the character encoded as " = 8 1 "

I am on a macintosh so the tm symbol is [option + 2] but when i code this it displays as a superscript "a" in the email. Does anybody have any suggestions?

Fopen GB2312 Encoding Problem
I am trying to read in a url which is encoded in GB2312 (http://
top.baidu.com/winkvane.html). I have tried other pages with this
encoding and each time I get a connection time out error. It seems
that fopen cannot open a webpage in GB2312. Is there a way around
this? Has anyone else had this sort of problem?

Here is an example with some simple code (using PHP5):

$file = fopen("http://top.baidu.com/winkvane.html", "r") or
exit("Unable to open file!");

while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);

Encoding Problem - Parsing An Xml File
I have a problem while parsing an xml file. The file is a backup from moodle (moodle.xml). When i open the file with one of my editors and setting Encoding to utf8 font courier standard or greek characters the editor can see all greek strings contained within the file perfectly. On the other hand when i try to open it with php parse it and then display it on a web page the data from the file come out like latin characters like (A~ atilde)(o: o umplaud) and others
like this. Updating moodle is not an option so i have to find a workaround. Has anybody heard of something like this?

Question About File Upload Encoding
If I drop a form onto my page that allows file uploads, I know well
enough how to handle the file upload in the server side via PHP.

However, I have a question: when my browser actually *sends* a binary
file (e.g., an image), does it encode it somehow for the upload? Or
does it simply send a raw bytestream?

The reason I am asking is that I am in the process of transferring some
images from one photo gallery to another (in Drupal). Mapping the two
database schemas has proved to be a little tricky, and I am thinking
it would be simpler to use the web interface to re-upload the various
images.

However, rather than do it one at a time, I'd just as soon write a PHP
script that would traverse through the old photo gallery files, and
upload them via HTTP POST (along with other relevant details, such as
descriptive text) and let the web interface make sure that the
database.

I'm comfortable with regular HTTP POST mechanisms, and doing them
programmatically with PHP, but I've never uploaded files that way.
Anything I should know? For example, do they need to be encoded
somehow before upload? Or can I just read in the raw bytestream, and
voila, there we go?

Writing Euro Symbol With Utf Encoding
I am writing a string from the database into a text file which contains
"Euro" symbol . I have tried using iconv() and utf_encode and
mb_convert_encoding() functions to convert the string to Unicode but the
text file created has just a square box in place of the Euro symbol. Can
anybody help me in this matter ?

Submit Form Data In Particular Encoding
I use some forms with search fields to look up some terms in external dictionaries. However, data need to be send in particular charset (for example, page with external dictionary uses windows-1250, so I need to submit data in windows-1250 charset to work properly).

I tried to use form's attribute accept-charset for this - works fine in FF, but not in IE, it seems to ignore this attribute. I also tried to set POST parameters in header manually in desired charset, it would might work, but then the page gets loaded without CSS etc, bare HTML gets downloaded only..

Error While Encoding A Txt File To Win-1252
I have a problem with encoding a file .txt to win-1252.

$text = recode_string("ISO-8859-1..win-1252", $text);

but I get the following error message:

Fatal error: Call to undefined function: recode_string()

the same when I trie to recode the whole file

with recode_file.


Copyright © 2005-08 www.BigResource.com, All rights reserved