php-general Digest 26 Feb 2006 20:15:09 -0000 Issue 3986
Topics (messages 231096 through 231112):
Parsing PHP variables in XML document
231096 by: Ivan Nedialkov
231100 by: Bogdan Ribic
231101 by: Bogdan Ribic
231104 by: chris smith
Re: How do I read Exif data without a file?
231097 by: Sameer N Ingole
231107 by: tedd
231110 by: Sameer N Ingole
Re: How can I make postgre execute file with SQL code, on windows platform
231098 by: Bogdan Ribic
231099 by: chris smith
Cookies in non-frame sites
231102 by: emil.vanster.nu
231103 by: chris smith
231105 by: Bogdan Ribic
Re: Linux distributions and tools for Linux/Apache/PHP/MySQL dev
231106 by: Jens Kleikamp
installing freetds
231108 by: blackwater dev
Re: email to db
231109 by: Manuel Lemos
Re: PHP upgrade on Go Daddy virtual server
231111 by: Gerry Danen
Re: Expat + PHP Examples...
231112 by: Weber Sites LTD
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
php-general@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
Hi,
I have the following problem. I want to import data into my site via PHP
XML Parser, but I also want to include php string variables into
the .xml file and when the xml file is parsed the variables are replaced
whit the corresponding string.
So far all my attempts have been unsuccessful.
Here is the parser i have used
<?php
class XMLParser {
var $filename;
var $xml;
var $data;
function XMLParser($xml_file)
{
$this->filename = $xml_file;
$this->xml = xml_parser_create();
xml_set_object($this->xml, $this);
xml_set_element_handler($this->xml, 'startHandler',
'endHandler');
xml_set_character_data_handler($this->xml, 'dataHandler');
$this->parse($xml_file);
}
function parse($xml_file)
{
if (!($fp = fopen($xml_file, 'r'))) {
die('Cannot open XML data file: '.$xml_file);
return false;
}
$bytes_to_parse = 512;
while ($data = fread($fp, $bytes_to_parse)) {
$parse = xml_parse($this->xml, $data, feof($fp));
if (!$parse) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->xml)),
xml_get_current_line_number($this->xml)));
xml_parser_free($this->xml
);
}
}
return true;
}
function startHandler($parser, $name, $attributes)
{
$data['name'] = $name;
if ($attributes) { $data['attributes'] = $attributes; }
$this->data[] = $data;
}
function dataHandler($parser, $data)
{
if ($data = trim($data)) {
$index = count($this->data) - 1;
// begin multi-line bug fix (use the .= operator)
$this->data[$index]['content'] .= $data;
// end multi-line bug fix
}
}
function endHandler($parser, $name)
{
if (count($this->data) > 1) {
$data = array_pop($this->data);
$index = count($this->data) - 1;
$this->data[$index]['child'][] = $data;
}
}
}
$url = 'data.xml';
$myFile = new XMLParser($url);
echo "<PRE>";
print_r($myFile->data);
echo "</PRE>";
$foo3 = "foo3";
?>
here is a sample XML file
<?xml version='1.0'?>
<!DOCTYPE chapter SYSTEM "/just/a/test.dtd" [
<!ENTITY plainEntity "FOO entity">
<!ENTITY systemEntity SYSTEM "xmltest2.xml">
]>
<document>
<data>
foo1
</data>
<data>
foo2
</data>
<data>
<?php echo $foo3; ?>
</data>
<data>
foo4
</data>
<data>
foo5
</data>
</document>
and what I get is:
Array
(
[0] => Array
(
[name] => DOCUMENT
[child] => Array
(
[0] => Array
(
[name] => DATA
[content] => foo1
)
[1] => Array
(
[name] => DATA
[content] => foo2
)
[2] => Array
(
[name] => DATA
)
[3] => Array
(
[name] => DATA
[content] => foo4
)
[4] => Array
(
[name] => DATA
[content] => foo5
)
)
)
)
So I want $myFile->data[0][child][2][content] to be equal to $foo3
--- End Message ---
--- Begin Message ---
Hi Ivan,
You might be able to use output buffering in conjunction with
including your xml file. Something like:
ob_start();
include $xml_file;
$content = ob_end_flush();
and then parse the $content string. If you are doing this from within
a function and you want access to global variables, you should import
all global variables first, via extract($GLOBALS);
Btw, this is just an idea, and untested - use at your own risk :)
Boban.
Ivan Nedialkov wrote:
Hi,
I have the following problem. I want to import data into my site via PHP
XML Parser, but I also want to include php string variables into
the .xml file and when the xml file is parsed the variables are replaced
whit the corresponding string.
So far all my attempts have been unsuccessful.
Here is the parser i have used
<?php
class XMLParser {
var $filename;
var $xml;
var $data;
function XMLParser($xml_file)
{
$this->filename = $xml_file;
$this->xml = xml_parser_create();
xml_set_object($this->xml, $this);
xml_set_element_handler($this->xml, 'startHandler',
'endHandler');
xml_set_character_data_handler($this->xml, 'dataHandler');
$this->parse($xml_file);
}
function parse($xml_file)
{
if (!($fp = fopen($xml_file, 'r'))) {
die('Cannot open XML data file: '.$xml_file);
return false;
}
$bytes_to_parse = 512;
while ($data = fread($fp, $bytes_to_parse)) {
$parse = xml_parse($this->xml, $data, feof($fp));
if (!$parse) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->xml)),
xml_get_current_line_number($this->xml)));
xml_parser_free($this->xml
);
}
}
return true;
}
function startHandler($parser, $name, $attributes)
{
$data['name'] = $name;
if ($attributes) { $data['attributes'] = $attributes; }
$this->data[] = $data;
}
function dataHandler($parser, $data)
{
if ($data = trim($data)) {
$index = count($this->data) - 1;
// begin multi-line bug fix (use the .= operator)
$this->data[$index]['content'] .= $data;
// end multi-line bug fix
}
}
function endHandler($parser, $name)
{
if (count($this->data) > 1) {
$data = array_pop($this->data);
$index = count($this->data) - 1;
$this->data[$index]['child'][] = $data;
}
}
}
$url = 'data.xml';
$myFile = new XMLParser($url);
echo "<PRE>";
print_r($myFile->data);
echo "</PRE>";
$foo3 = "foo3";
?>
here is a sample XML file
<?xml version='1.0'?>
<!DOCTYPE chapter SYSTEM "/just/a/test.dtd" [
<!ENTITY plainEntity "FOO entity">
<!ENTITY systemEntity SYSTEM "xmltest2.xml">
]>
<document>
<data>
foo1
</data>
<data>
foo2
</data>
<data>
<?php echo $foo3; ?>
</data>
<data>
foo4
</data>
<data>
foo5
</data>
</document>
and what I get is:
Array
(
[0] => Array
(
[name] => DOCUMENT
[child] => Array
(
[0] => Array
(
[name] => DATA
[content] => foo1
)
[1] => Array
(
[name] => DATA
[content] => foo2
)
[2] => Array
(
[name] => DATA
)
[3] => Array
(
[name] => DATA
[content] => foo4
)
[4] => Array
(
[name] => DATA
[content] => foo5
)
)
)
)
So I want $myFile->data[0][child][2][content] to be equal to $foo3
--
Open source PHP code generator for DB operations
http://sourceforge.net/projects/bfrcg/
--- End Message ---
--- Begin Message ---
Hmmm, come to think of it, it would only work if short_open_tags ini
directive is turned OFF, which in most cases it won't be :(
Bogdan Ribic wrote:
Hi Ivan,
You might be able to use output buffering in conjunction with
including your xml file. Something like:
ob_start();
include $xml_file;
$content = ob_end_flush();
and then parse the $content string. If you are doing this from within
a function and you want access to global variables, you should import
all global variables first, via extract($GLOBALS);
Btw, this is just an idea, and untested - use at your own risk :)
Boban.
--
Open source PHP code generator for DB operations
http://sourceforge.net/projects/bfrcg/
--- End Message ---
--- Begin Message ---
On 2/26/06, Bogdan Ribic <[EMAIL PROTECTED]> wrote:
> Hmmm, come to think of it, it would only work if short_open_tags ini
> directive is turned OFF, which in most cases it won't be :(
You can turn it off with a htaccess file.
--- End Message ---
--- Begin Message ---
Niels wrote:
I think you misunderstand the situation.
[snip]
I've got a database of images (image data) and their exif data, I'm not
uploading any files. I want to make new entries in that DB, new images that
are thumbnails of the present images. I can do that without creating files,
but I can't get exif data of these thumbnails, because there are no files.
The exif data for the thumbnails isn't the same as for the full images.
In PHP its not easy to keep EXIF data of JPEG or TIF files as it is if
you use PHP functions to recreate the temporary files in some dir.
Basically when you use tempnam() it creates a temporary file. To get the
thumbnails you must rewrite the resized file to some place (if you want
real thumbnail image). You cannot preserve exif data with any of PHP
functions available. You probably have to use some specially developed
code to write exif data. I tried this class
http://www.zonageek.com/software/php/jpeg/
I tried to use it but either it could not write all the exif data or I
was not calling required functions properly.. It requires pear..
Other you can try is http://pel.sourceforge.net/
But both of these will require you to write a resized image and then
write exif data (common for both, original and resized) retrieved from
the original image to the new thumbnail you generated with additional
image specific exif info.
Best is to maintain thumbnails.. with exif data written in it too.
Regards,
--
Sameer N. Ingole
Blog: http://weblogic.noroot.org/
---
Better to light one candle than to curse the darkness.
--- End Message ---
--- Begin Message ---
Sameer said:
To get the thumbnails you must rewrite the resized file to some
place (if you want real thumbnail image).
No, that's not correct. You can take an image from a db, create a
thumbnail while it is in memory and display it. You don't need to
make it a file first.
tedd
--
--------------------------------------------------------------------------------
http://sperling.com
--- End Message ---
--- Begin Message ---
tedd wrote:
Sameer said:
To get the thumbnails you must rewrite the resized file to some place
(if you want real thumbnail image).
No, that's not correct. You can take an image from a db, create a
thumbnail while it is in memory and display it. You don't need to make
it a file first.
That *is* correct. You must rewrite the resized file to some place and
that place can be /dev/foo (memory or disk). I did not say you must
write it to /disk/.
Regards,
--
Sameer N. Ingole
Blog: http://weblogic.noroot.org/
---
Better to light one candle than to curse the darkness.
PS: Please reply to the list only. You probably hit "reply all". I got two
copies of same message.
--- End Message ---
--- Begin Message ---
Hi Chris,
Goal was to get postgre to execute/import an sql dump file, ie not to
write import-export functionality myself. In the end, I used piping,
something like this:
system("type $filename | \"C:\Program
Files\PostgreSQL\8.1\bin\psql.exe\" -h localhost -p 5432 X6tmp
\"postgres\"");
But thanx anyway :)
Boban.
chris smith wrote:
pg_connect($connection_string);
pg_query("drop schema public");
....
import data
....
or am I missing something here?
You might be better of not doing this with php.
Create the dump on the first machine.
Copy the dump (scp, rsync, copy via samba-mounted drive, whatever)
import it
It depends what your end goal is.
--
Open source PHP code generator for DB operations
http://sourceforge.net/projects/bfrcg/
--- End Message ---
--- Begin Message ---
> Goal was to get postgre to execute/import an sql dump file, ie not to
> write import-export functionality myself. In the end, I used piping,
> something like this:
>
> system("type $filename | \"C:\Program
> Files\PostgreSQL\8.1\bin\psql.exe\" -h localhost -p 5432 X6tmp
> \"postgres\"");
>
> But thanx anyway :)
>
> Boban.
Which is why I said:
---------
You might be better of not doing this with php.
Create the dump on the first machine.
Copy the dump (scp, rsync, copy via samba-mounted drive, whatever)
import it
---------
--- End Message ---
--- Begin Message ---
Hello,
Most sites today seems to be based on this style:
include(top);
include(current_page);
include(bottom);
If one wants to set cookies from current_page, how should that be handled with
as clean source as possible?
Before I had the top and bottom output as functions that are called from each
page, so I can call header stuff before it's executed. But it's not a very good
looking approach.
I did it like this in every page:
include(top_bottom_lib);
// cookie stuff
echo getTopPage();
// page stuff
echo getBottomPage();
I hope you understand my problem.
Thanks
Best regards Emil
--- End Message ---
--- Begin Message ---
> Most sites today seems to be based on this style:
>
> include(top);
> include(current_page);
> include(bottom);
>
> If one wants to set cookies from current_page, how should that be handled
> with as clean source as possible?
>From the php manual:
Like other headers, cookies must be sent before any output from your
script (this is a protocol restriction). This requires that you place
calls to this function prior to any output, including <html> and
<head> tags as well as any whitespace. If output exists prior to
calling this function, setcookie() will fail and return FALSE.
So it has to go before ALL output otherwise it will fail. You're stuck
with putting it in the 'top' file or at least before you echo any
output.
--- End Message ---
--- Begin Message ---
You can also use output buffering, write cookies from anywhere, and at
the end of execution buffers will auto-flush.
[EMAIL PROTECTED] wrote:
Hello,
Most sites today seems to be based on this style:
include(top);
include(current_page);
include(bottom);
If one wants to set cookies from current_page, how should that be handled with
as clean source as possible?
Before I had the top and bottom output as functions that are called from each
page, so I can call header stuff before it's executed. But it's not a very good
looking approach.
--
Open source PHP code generator for DB operations
http://sourceforge.net/projects/bfrcg/
--- End Message ---
--- Begin Message ---
Chris Lott wrote:
I'm making the switch from Windows to Linux for mydesktop and
development environment and would greatly appreciate suggestions for
development tools on this platform. Ubuntu seems to be getting all the
press, but suggestions about Linux distributions are welcome as well!
c
Just for editing php files under linux I found the eclipse plugin
http://www.phpeclipse.de.
Very nice screenshot:
http://www.flickr.com/photo_zoom.gne?id=101196627&size=o
Also it seems that there will be a more powerfull php environment for
eclipse in the future by Zend and IBM.
http://www.eclipse.org/proposals/php-ide/ - promising! :)
Best Regards,
Jens
--- End Message ---
--- Begin Message ---
I am a linux newbie but just compiled freetds on my fedora box. I used the
basic options:
./configure
make
make install
make clean
According to the docs it should install to /usr/local/freetds
After all this I don't have a freetds folder in /local/. If I go into
/usr/local/bin, I do have a tsql which I believe are part of freetds so I
think it installed. Where do I set the directory when I recompile php
--with-mssql?
Thanks!
--- End Message ---
--- Begin Message ---
Hello,
on 02/24/2006 11:28 PM Mark said the following:
> Does anyone know if its possible or how difficult it would be to have a user
> send an email from outlook express to a websites mysql database and update
> records.
If the message goes to an address with a POP3 mailbox, you can always
get the message body using a POP3 client script using for instance a
class like this:
http://www.phpclasses.org/pop3class
--
Regards,
Manuel Lemos
Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
--- End Message ---
--- Begin Message ---
Have you tried GoDaddy support?
On 2/25/06, Nicolas Verhaeghe <[EMAIL PROTECTED]> wrote:
>
> Has anybody heard (or done it himself) how to upgrade PHP on a Go Daddy
> virtual server?
>
> Current version is 4.3.11 and I'd like to upgrade to 5.1.2.
>
> All I know is that this server is a Red Hat Fedora 2.
>
> I have SSH access and root as well.
>
--- End Message ---
--- Begin Message ---
I'm not sure if this is the same thing (expat and patxml)
http://www.weberdev.com/ViewArticle-441.html
http://www.weberdev.com/ViewArticle-444.html
berber
-----Original Message-----
From: Gustav Wiberg [mailto:[EMAIL PROTECTED]
Sent: Sunday, February 26, 2006 12:19 AM
To: PHP General
Subject: [PHP] Expat + PHP Examples...
Hi there!
I've found out that I can use expat XML, but I can't figure out HOW to
use... it seems simple, but I tried and can't figure it out...
I'd like to get retrieve info from
http://www.frisim.com/frisim/servlet/rss?searchString=google
and convert it to html...
I've read a lot a of text for Expat, but found no really good example (I
found one at phpbuilder.com but with links that went to xml-files that
didn't exists ):
Someone who have used expat.. ..and can give me a hint...
/G
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
--- End Message ---