php-general Digest 27 Nov 2007 01:45:12 -0000 Issue 5149

Topics (messages 265022 through 265038):

Re: Session cookie doesn't work
        265022 by: Teck
        265024 by: metastable

Re: How to ask "if private IP"?
        265023 by: Jochem Maas
        265031 by: William Betts

how do i get a printout of original multipart post data
        265025 by: Olav Mørkrid
        265026 by: Robert.Degen.rwth-aachen.de

Re: Code Critique Please :)
        265027 by: Philip Thompson
        265028 by: Martin Alterisio

Re: URL Parsing...
        265029 by: Richard Heyes
        265034 by: Jochem Maas

Re: session_destroy AND reload a page
        265030 by: Philip Thompson

Emailing dilemma
        265032 by: George Pitcher
        265036 by: Miles Thompson

Representing microtime() values
        265033 by: Tomi Kaistila

Re: dgettext vs. xgettext
        265035 by: news_yodpeirs.thoftware.de

SimpleXML error
        265037 by: Skip Evans
        265038 by: Casey

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:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Thanks Stijn for your advice.

I wonder if my "session.save_path /var/lib/php4" is correct. Who should be the owner of the directory? Is there any permission settings I need to care about?

I also consider "session.cookie_path /". After searching, it means cookies are avaiable for all the directories under, let's say, http://www.example.com/ . So if I work only at http://example.com/myspace , would it be better to change the path? What permissions are required to the path?

Sessions work when I use URL as paramers such as http://www.example.com?SESSID=3u498q7rtq34897 . But I want to make session cookies work.

- T

On Nov 26, 2007, at 8:12 PM, metastable wrote:

Hey,

Your session will expire, regardless of the call to session_set_cookie_params. If you're looking to propagate a session across time, you should look at keeping your session data in a database (google: session_set_save_handler, there's a good tutorial on the zend site), then calling a table row based on a cookie you set independently of the session.

Based on the configuration you presented, I don't see why the following code shouldn't give you the expected results:

## test1.php  ##
<?php
session_start();
$_SESSION['name'] = 'Kevin';
?>
<a href="test2.php">test2</a>
###########

## test2.php ##
<?php
session_start();
echo $_SESSION['name'];
// If the above doesn't work, try doing a print_r($_SESSION) and let us know what that brings up.
?>
###########

If for some reason I am not aware off, your typical setup doesn't automatically save the session before exiting the script, you could try ending your scripts with:
<?php
session_write_close();
?>


As a general tip, I suggest you set your error_reporting to E_ALL on your development machine. That would print out a notice when a certain index or key is not set in an array.


best regards,

Stijn


Teck wrote:
Hi,

I'm working to use cookie to maintain session data across multiple pages in PHP4.42. I have the following two scripts, where I think the second file outputs a data in a session variable.

file 1 - test_1.php #####################

<?php
session_set_cookie_params(360 * 24 * 3600);
session_start();

$_SESSION['name'] = "Kevn";
?>

<a href="test_2.php?<php? echo SID ?>">Go next</a>

##########################################

file 2 - test_2.php ######################


<?php

session_start();
echo $_SESSION['name']; // Here I expect to show the word "Kevin"

?>


##########################################

phpinfo() tells me that
* Session Support enabled
* session.auto_start Off
* session.bug_compat_42 On
* session.bug_compat_warn On
* session.cache_expire 180
* session.cache_limiter nocache
* session.cookie_domain no value
* session.cookie_path /
* session.cookie_secure Off
* session.entropy_file no value
* session.entropy_length 0
* session.gc_divisor 100
* session.gc_maxlifetime 1440
* session.gc_probability 0
* session.name PHPSESSID
* session.referer_check no value
* session.save_handler files
* session.save_path /var/lib/php4
* session.use_cookies On
* session.use_only_cookies On
* session.use_trans_sid On

What am I missing?

In file 1, I also tried "<a href="test_2.php>Go next</a> .
I've been learning PHP using various books and websites. Still I don't solve this issue.

Any help would be apprecaited.




--- End Message ---
--- Begin Message ---
Hey Teck,

If the session works when you append the session id to the URL, I would think that the session_save_path is ok and writable. You can assure yourself that it is indeed the case, by going to your session.save_path and checking out the contents of the session files there. Better practice might be to create a directory under /tmp, chmod it to 700 and use that as the session.save_path. In general, it will be the user running apache that writes to all the paths, so at least that user (probably apache:apache) needs read, write and execute permissions for the directory.

I don't know anything about the cookie_path, and can't find a decent explanation as to what it does at the moment.

I would say your browser rejects cookies, or is at least setup to reject cookies from your domain (localhost, I assume). Could you check that out ?


Greetz,

Stijn



Teck wrote:
Thanks Stijn for your advice.

I wonder if my "session.save_path /var/lib/php4" is correct. Who should be the owner of the directory? Is there any permission settings I need to care about?

I also consider "session.cookie_path /". After searching, it means cookies are avaiable for all the directories under, let's say, http://www.example.com/ . So if I work only at http://example.com/myspace , would it be better to change the path? What permissions are required to the path?

Sessions work when I use URL as paramers such as http://www.example.com?SESSID=3u498q7rtq34897 . But I want to make session cookies work.

- T

On Nov 26, 2007, at 8:12 PM, metastable wrote:

Hey,

Your session will expire, regardless of the call to session_set_cookie_params. If you're looking to propagate a session across time, you should look at keeping your session data in a database (google: session_set_save_handler, there's a good tutorial on the zend site), then calling a table row based on a cookie you set independently of the session.

Based on the configuration you presented, I don't see why the following code shouldn't give you the expected results:

## test1.php  ##
<?php
session_start();
$_SESSION['name'] = 'Kevin';
?>
<a href="test2.php">test2</a>
###########

## test2.php ##
<?php
session_start();
echo $_SESSION['name'];
// If the above doesn't work, try doing a print_r($_SESSION) and let us know what that brings up.
?>
###########

If for some reason I am not aware off, your typical setup doesn't automatically save the session before exiting the script, you could try ending your scripts with:
<?php
session_write_close();
?>


As a general tip, I suggest you set your error_reporting to E_ALL on your development machine. That would print out a notice when a certain index or key is not set in an array.


best regards,

Stijn


Teck wrote:
Hi,

I'm working to use cookie to maintain session data across multiple pages in PHP4.42. I have the following two scripts, where I think the second file outputs a data in a session variable.

file 1 - test_1.php #####################

<?php
session_set_cookie_params(360 * 24 * 3600);
session_start();

$_SESSION['name'] = "Kevn";
?>

<a href="test_2.php?<php? echo SID ?>">Go next</a>

##########################################

file 2 - test_2.php ######################


<?php

session_start();
echo $_SESSION['name']; // Here I expect to show the word "Kevin"

?>


##########################################

phpinfo() tells me that
* Session Support enabled
* session.auto_start Off
* session.bug_compat_42 On
* session.bug_compat_warn On
* session.cache_expire 180
* session.cache_limiter nocache
* session.cookie_domain no value
* session.cookie_path /
* session.cookie_secure Off
* session.entropy_file no value
* session.entropy_length 0
* session.gc_divisor 100
* session.gc_maxlifetime 1440
* session.gc_probability 0
* session.name PHPSESSID
* session.referer_check no value
* session.save_handler files
* session.save_path /var/lib/php4
* session.use_cookies On
* session.use_only_cookies On
* session.use_trans_sid On

What am I missing?

In file 1, I also tried "<a href="test_2.php>Go next</a> .
I've been learning PHP using various books and websites. Still I don't solve this issue.

Any help would be apprecaited.




--- End Message ---
--- Begin Message ---
Ronald, I really dont care if my email doesn't reach you, making normal people 
jump
through hoops because you want to avoid spam is not the right way to do things,
next time I'll remember not to answer your questions as your not going to
['be able to'] read my answers:

<BLA BLA BLA>
This message was created automatically by mail delivery software (TMDA).

Your message attached below is being held because the address
<[EMAIL PROTECTED]> has not been verified.

To release your message for delivery, please send an empty message
to the following address, or use your mailer's "Reply" feature.

   [EMAIL PROTECTED]

This confirmation verifies that your message is legitimate and not
junk-mail. You should only have to confirm your address once.

If you do not respond to this confirmation request within 14 days,
your message will not be delivered.
</BLA BLA BLA>



Jochem Maas wrote:
> Ronald Wiplinger wrote:
>> I use $aa=$_SERVER["REMOTE_ADDR"];
>>

--- End Message ---
--- Begin Message ---
Below is a quick example. This isn't the best way to do it, just
another way. I personally would convert them to integers then compare
instead of doing it the way I'm doing it below.

<?php

function privateIP($ip)
{
        if ( (($ip >= "10.0.0.0") && ($ip <= "10.255.255.255")) ||
             (($ip >= "192.168.0.0")  && ($ip <= "192.168.255.255")) ||
             (($ip >= "172.16.0.0") && ($ip <= "172.31.255.255")) ) {
                return true;
        }
        return false;
}

if (privateIP("192.168.1.1")) {
        print "hmm";
}
?>

William Betts
http://www.phpbakery.com

On Nov 26, 2007 6:08 AM, Jochem Maas <[EMAIL PROTECTED]> wrote:
> Ronald, I really dont care if my email doesn't reach you, making normal 
> people jump
> through hoops because you want to avoid spam is not the right way to do 
> things,
> next time I'll remember not to answer your questions as your not going to
> ['be able to'] read my answers:
>
> <BLA BLA BLA>
> This message was created automatically by mail delivery software (TMDA).
>
> Your message attached below is being held because the address
> <[EMAIL PROTECTED]> has not been verified.
>
> To release your message for delivery, please send an empty message
> to the following address, or use your mailer's "Reply" feature.
>
>    [EMAIL PROTECTED]
>
> This confirmation verifies that your message is legitimate and not
> junk-mail. You should only have to confirm your address once.
>
> If you do not respond to this confirmation request within 14 days,
> your message will not be delivered.
> </BLA BLA BLA>
>
>
>
> Jochem Maas wrote:
> > Ronald Wiplinger wrote:
> >> I use $aa=$_SERVER["REMOTE_ADDR"];
> >>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
hello


how can i get a raw and untouched printout of a multipart/form-data
POST? i need this to analyze what certain user agents do wrong when
uploading files.

what happens is that php just fails to put files into $_FILES, and
gives no way of seeing the original posting and exactly what is wrong
with it.

according to the manual, neither "always_populate_raw_post_data" nor
<php://input> work for multipart/form-data.

--- End Message ---
--- Begin Message ---
If you're with linux try netcat (nc) at listening mode.

Something like (not exactly)

nc -vtlp 80

and then submut against any localhost url.

greetings....


----- Ursprüngliche Nachricht -----
Von: Olav Mørkrid <[EMAIL PROTECTED]>
Datum: Montag, November 26, 2007 1:52 pm
Betreff: [PHP] how do i get a printout of original multipart post data
An: [EMAIL PROTECTED]

> hello
> 
> 
> how can i get a raw and untouched printout of a multipart/form-data
> POST? i need this to analyze what certain user agents do wrong when
> uploading files.
> 
> what happens is that php just fails to put files into $_FILES, and
> gives no way of seeing the original posting and exactly what is wrong
> with it.
> 
> according to the manual, neither "always_populate_raw_post_data" nor
> <php://input> work for multipart/form-data.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--- End Message ---
--- Begin Message ---
On Nov 22, 2007 11:52 AM, Robert Cummings <[EMAIL PROTECTED]> wrote:

> On Thu, 2007-11-22 at 12:46 -0500, Oscar Gosdinski wrote:
> >
> > There is something that i always wonder about Singleton pattern in
> > PHP, do you really have a benefit using this pattern in PHP? The idea
> > behind this pattern is that only one instance of the class is created,
> > it works great in Java because all requests are processed inside a JVM
> > and this instance created will really be the only one defined. Because
> > in PHP every request has its own environment, you will have several
> > instances of this class per request processed.
>
> Doesn't matter... you may have multiple requests for the object within
> the same HTTP request. Singleton pattern is very valid in PHP.
>
> Cheers,
> Rob



I don't know if I should be embarrassed or not, but I'd not heard of the
Singleton pattern before. So, I enlightened myself and learned something new
(and it's only 9:00 am on a Monday morning!). =D Google it or click here -
it's pretty easy reading...

http://en.wikibooks.org/wiki/Computer_Science/Design_Patterns

~Philip

--- End Message ---
--- Begin Message ---
2007/11/21, Simeon F. Willbanks <[EMAIL PROTECTED]>:
>
> Hello,
>
> I am trying to increase my knowledge and understanding of OO and OO
> Design Patterns.  I'd like to request a critique of a program that
> extracts MySQL table information and translates it into XML.  In the
> program, I tried to accomplish a few things:
>
> 1. Correct use of ADOdb
> 2. Closely match the PEAR coding standards
>         - I encode my scripts in UTF-8
>         - Not all indents are 4 spaces, but I have switched my IDE to
> treat
> tabs as four spaces
>         - My phpDoc comments could probably use some tweaking
> 3. Object Oriented principles
> 4. Strategy Design Pattern
>         - Interface used for column attribute parsing
>
> My overall goal is to use these xml files as a starting point to write
> a DAO with the Data Mapper Pattern.
>
> Here are the related files to peruse:
> http://simeons.net/code/datamapper/sql/photo_portfolio.sql
>         - SQL dump
> http://simeons.net/code/datamapper/mysql_to_xml_oo.phps
>         - Calling script
> http://simeons.net/code/datamapper/helpers/autoload.phps
>         - Auto load classes
> http://simeons.net/code/datamapper/classes/DB.phps
>         - ADOdb connection
> http://simeons.net/code/datamapper/classes/MySQLToXML.phps
>         - MySQL extraction and parsing
>         - XML writing
>
> Here are the outputted xml files:
> http://simeons.net/code/datamapper/xmldatamaps/album.xml
> http://simeons.net/code/datamapper/xmldatamaps/photo.xml
> http://simeons.net/code/datamapper/xmldatamaps/comment.xml
>
> Any comments are appreciated.
>
> Thanks,
> Simeon
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
My 2 cents:

1) Do not use __autoload. Use SPL's spl_autoload_register().

2) Are you using one file per class? If not, you should.

3) Class names should be as self-explanatory as possible.
They should indicate what the class purpose is.

For example: MySQLToXML is too ambiguous as a class name. What does it do?
What aspect of MySQL translates to an XML?
MySQLToXML could be the name of the class package but not the name of the
class. I would have named it: MySQLDataToXMLExporter. Or preceding the name
with the package name: MySQLToXML_XMLExporter.

4) Class names shouldn't be verb conjugations. Use nouns instead.

e.g.: ParseDatabaseColumnAttribute is wrong, use something like
DatabaseColumnExporter or DatabaseColumnConverter or DatabaseColumnParser
(is not clear what its purpose is).

5) The use of __get with unrestricted access breaks encapsulation.

Your definition of __get in MySQLToXML provides access to any private var.
Did you actually intended that?
It doesn't look good anyway. Seems like a nasty workaround.

6) Function names should explain their purposes.

_setXmlDocuments doesn't set xml documents, it's actually building them.

Also, functions that start with get and set are usually expected to be just
getter and setters, which is usually associated with O(1) operations, or
O(logN)/O(N) in containers (meaning that it's not expected that a get or set
functions does more than just get or set a variable).

7) DON'T BE A SPORT COMMENTATOR!!!!!

Putting a comment on each line of code and just saying what it does actually
generates the opposite effect. It harms code readability and
maintainability. Also, it's a common sign of someone who was just forced to
put comments and didn't know how to do it.

You should use inline comments where relevant. If code is self-explanatory
(to a certain degree), inline comments are just a bother. You should use
inline comments whenever the action being done by the code cannot be grasped
just by looking at it, or whenever the code differs too much from usual
constructions that someone might not see what it's actually doing.

For example, compare the following:

// set table name
$tableName = $tableResultSet->fields[0];
// set xml document version and character encoding
$this->_xmlDocuments[$tableName] = '<?xml version="1.0" encoding="UTF-8"?>'
. "\n";
// open _xmlDocuments element for this table
$this->_xmlDocuments[$tableName] .= '<' . $tableName . '>' . "\n";
// fetch array with associative keys
$this->_dbConnection->setFetchMode(ADODB_FETCH_ASSOC);
// ADOdb result set of fields in the current table
$columnResultSet =
$this->_dbConnection->execute(sprintf($this->_dbConnection->metaColumnsSQL,
$tableName));
// loop until the end of the fields result set
while (!$columnResultSet->EOF) {

with this:

// loop initialization
$tableName = $tableResultSet->fields[0];
$this->_xmlDocuments[$tableName] = '<?xml version="1.0" encoding="UTF-8"?>'
. "\n";
$this->_xmlDocuments[$tableName] .= '<' . $tableName . '>' . "\n";
// we need associative arrays
$this->_dbConnection->setFetchMode(ADODB_FETCH_ASSOC);
$columnResultSet =
$this->_dbConnection->execute(sprintf($this->_dbConnection->metaColumnsSQL,
$tableName));
// loop through every record
while (!$columnResultSet->EOF) {


8) It seems that it's not the strategy pattern what you're using but the
builder pattern.

I'm not the right person to explain the difference, but I'll try.

The strategy pattern is used to separate an algorithm from its implementor.
The builder pattern is used when you're building a multi-part structure and
you don't want to statically bind the building process to a particular
abstraction. This is what I think you're doing. You need to build the XML,
and delegate the construction to an abstraction who actually knows how to
build its parts, through a common interface. You could use a strategy
pattern if you need to output in different formats, each shares the same
data structure but the algorithm to do the export is different.

--- End Message ---
--- Begin Message ---
Chris wrote:
Richard Heyes wrote:
well if you take a string (filename) and wish to change the end of it somone then I don't think str_replace() is the correct function. what's to say a script
doesn't exist called 'my.cfm.php'?

How does this:

/\.cfm$/

take into account that?

$ in regex's means 'end of string' - so it will only match .cfm at the very end of the string.

Indeed, so how does the regex take into account ".cfm.php"? It doesn't. If it doesn't have a .cfm extension, it won't match.

--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
> Chris wrote:
>> Richard Heyes wrote:
>>>> well if you take a string (filename) and wish to change the end of
>>>> it somone
>>>> then I don't think str_replace() is the correct function. what's to
>>>> say a script
>>>> doesn't exist called 'my.cfm.php'?
>>>
>>> How does this:
>>>
>>> /\.cfm$/
>>>
>>> take into account that?
>>
>> $ in regex's means 'end of string' - so it will only match .cfm at the
>> very end of the string.
> 
> Indeed, so how does the regex take into account ".cfm.php"? It doesn't.
> If it doesn't have a .cfm extension, it won't match.

because the question was "I want to replace the extension '.cfm' with 
'-meta.cfm',
which I assumed meant the OP didn't want 'my.cfm.php' to become 
'my-meta.cfm.php'
and a str_replace('.cfm', '-meta.cfm', $foo) would not be correct in that 
situation.

hopefully now the use of preg_replace() in my example makes sense.

oh and I forget to add delimeters to the regexps in my examples, which was a 
stupid
oversight.

> 

--- End Message ---
--- Begin Message ---
On Nov 26, 2007 12:45 AM, Chris <[EMAIL PROTECTED]> wrote:

> Ronald Wiplinger wrote:
> > If my user wants to logout, I want that the session will be destroyed
> > and that he must start with the first page again (index.php) and a new
> > session.
> >
> > Whatever I try he always gets the old sessions or he does not come to
> > the first page.
>
> What code do you have?
>


A very crude way to do this....

$_SESSION = array();

However, this will destroy EVERY variable within the session. This is bad if
you have multiple sites on one server. To organize your session variables,
you may try storing them as......

$_SESSION['aSiteName']['is_logged_in'],
$_SESSION['aSiteName']['var1'], $_SESSION['aSiteName']['var2'],
etc

To destroy all variables within this site ('aSiteName' being this example),
do...

$_SESSION['aSiteName'] = array();

OR

unset ($_SESSION['aSiteName']);

HTH
~Philip

--- End Message ---
--- Begin Message ---
Hi,

I have almost 30 websites that use PEAR::Mail to send emails on behalf of
users at universities (one site for each) to lecturers at the same
university.

The problem I have is that if a lecturer sets an 'Out of Office' status, it
gets bounced back to my server instead of to the user at the university.

I did have the 'From' set to the user's email address, but that wasn't very
successful ats it caused problems with the universities' anti-spam systems.

I've tried using ini_set('sendmail_from',$useremail); but that doesn't seem
to work either.

Can anyone point me in the right direction, please?


Cheers

George in Edinburgh

--- End Message ---
--- Begin Message ---
George,

Had this problem a year ago, although I'm not using PEAR. Have a look at
http://ca3.php.net/manual/en/function.mail.php
and this down in the additional_parameters(optional) section:

"For example, this can be used to set the envelope sender address when using
sendmail with the *-f* sendmail option."

It is not well documented, don't know if this helps, but it may get you
started.

Cheers - Miles

On Nov 26, 2007 3:21 PM, George Pitcher <[EMAIL PROTECTED]> wrote:

> Hi,
>
> I have almost 30 websites that use PEAR::Mail to send emails on behalf of
> users at universities (one site for each) to lecturers at the same
> university.
>
> The problem I have is that if a lecturer sets an 'Out of Office' status,
> it
> gets bounced back to my server instead of to the user at the university.
>
> I did have the 'From' set to the user's email address, but that wasn't
> very
> successful ats it caused problems with the universities' anti-spam
> systems.
>
> I've tried using ini_set('sendmail_from',$useremail); but that doesn't
> seem
> to work either.
>
> Can anyone point me in the right direction, please?
>
>
> Cheers
>
> George in Edinburgh
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hi everyone

Here's a small problem that I haven't been able to figure out and hence I
figured I'd post and see if anyone can explain this to me.

It concerns the values that are being returned to me by the microtime()
function. When I run a simple line, e.g.

print microtime(true);

or

var_dump(microtime(true));

The result is usually something like: 1196104701.67.

This makes no sense to me. It is made even more perplexing by the fact that
when I run the timing example from microtime's manual page

http://www.php.net/manual/en/function.microtime.php (it's the bottom one,
for PHP 5)

I invariably get a result with loads of digits, like: 0.00072979927063
seconds. Does PHP hide the extra digits whenever I try to print it? I tried
force PHP to show them to me, but unless I am printing a direct result of a
calculation by two such numbers, I cannot get them show on the page. Even
round(microtime(), 6) does not seem to work. It only shows two digits.

How exactly does PHP handle these values internally? Does anyone know?

How about, is there a way around this?

This is important because my program is suppose to store and handle double
values and whenever I do calculations with them, I lose all but the two
digits along the way.


Tomi Kaistila
PHP Developer

--- End Message ---
--- Begin Message ---
No ideas? Am I the only one using different domains with dgettext? What's 
the sense of it if you can't get the translations apart?

Any hint is welcome ...

<[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
> Hi!
>
> I'm using dgettext() with different domains in one set of scripts (or even
> in one script). When extracting the messages with xgettext I would like to
> specify an option to get only messages for one domain, like getting all
> messages from calls to dgettext('foobar',...) and ignore all others.
> Otherwise it wouldn't be possible to know which message belongs to which
> domain. Did anyone else came across this problem? And, even more 
> interesing:
> Does anyone have a solution for this?
>
> With kind regards
> Thomas 

--- End Message ---
--- Begin Message ---
Hey all,

I have some XML files I need to parse and then display (they have HTML formatting in them as well).

They contain the following:

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//Gale//DTD Gale eBook Document DTD 20031113//EN" "galeeBkdoc.dtd">
<html gale:versionNumber="OEB 1.2, Gale 1.3">
<head>
<gale:docName gale:zzNumber="2536600565"/>
<gale:documentCitation>
<gale:pageRange>214-215</gale:pageRange>
</gale:documentCitation>
<title>Thomas Jefferson and the Revision of the Virginia Laws</title>
</head>

I am then attempting to extract the title with this:

$xml = simplexml_load_file(BASE_DIR.'/content/'.$r['filename']);
$title= $xml->title;

But in the browser I get the following warning.

namespace error : Namespace prefix gale for versionNumber on html is not defined...

Is this because it is not locating the file galeeBkdoc.dtd, which defines all the elements in the XML files?

It is located in the same directory as the content. I have also tried putting the complete path via HTTP in with the name of the DTD file with no luck.


Suggestions would be greatly appreciated.

Thanks!
Skip

--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX & DHTML development framework.
http://phpenguin.bigskypenguin.com/

--- End Message ---
--- Begin Message ---
I'm not sure, but try casting $xml->title to string, like this:

$title = (string) $xml->title;


On Nov 26, 2007, at 1:44 PM, Skip Evans <[EMAIL PROTECTED]> wrote:

Hey all,

I have some XML files I need to parse and then display (they have HTML formatting in them as well).

They contain the following:

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//Gale//DTD Gale eBook Document DTD 20031113//EN" "galeeBkdoc.dtd">
<html gale:versionNumber="OEB 1.2, Gale 1.3">
<head>
<gale:docName gale:zzNumber="2536600565"/>
<gale:documentCitation>
<gale:pageRange>214-215</gale:pageRange>
</gale:documentCitation>
<title>Thomas Jefferson and the Revision of the Virginia Laws</title>
</head>

I am then attempting to extract the title with this:

$xml = simplexml_load_file(BASE_DIR.'/content/'.$r['filename']);
$title= $xml->title;

But in the browser I get the following warning.

namespace error : Namespace prefix gale for versionNumber on html is not defined...

Is this because it is not locating the file galeeBkdoc.dtd, which defines all the elements in the XML files?

It is located in the same directory as the content. I have also tried putting the complete path via HTTP in with the name of the DTD file with no luck.


Suggestions would be greatly appreciated.

Thanks!
Skip

--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX & DHTML development framework.
http://phpenguin.bigskypenguin.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---

Reply via email to