[PHP] PHP Source File Encoding

2006-11-11 Thread C Drozdowski
Gotta a question whose answer should be really obvious to me but, for  
some reason, is just eluding me.


Which encodings can PHP handle for source files? I've been using  
iso-8859-1 but what about utf-8?


Thanks,

C Drozdowski

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



[PHP] Including class of Exception in exception message

2005-04-09 Thread C Drozdowski
I'm using Exceptions and variously handling them in try..catch blocks 
or defaulting to my set_exception_handler handler.
When I create an Exception I'd like to prepend the class of the 
Exception to the message. Can this be done with code or do I have to 
hard code the name of the Exception class into the message every time I 
throw the exception?

For Example:
I'd like to turn this...
throw new myException(myException: So this is it, we're going to die);
into...
throw new myException( CODE . : So this is it, we're going to die);
where CODE is some php code that refers to the class of the exception 
being thrown.

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


[PHP] Smart Trimming of UTF-8 Entities for Database

2005-04-07 Thread C Drozdowski
I need to be able to store UTF-8 characters from a form into a MySQL 
table. But I need to support pre-UTF-8 MySQL ( 4.1).

So I'm converting UTF-8 characters into their numeric entities (e.g. ñ 
= #241;).

The problem is that if the user enters a character that gets converted 
to an entity, the string might end up being longer than the field 
definition in the table allows.

For example, if I have a varchar(5) column and try to insert señor 
(which has been converted to sen#241;or), I get sen# in the table 
which is useless.

Has anyone dealt with this and if so how?
Thanks in advance for any advice, or pointers to any code that deals with this.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Why do I have to declare __set if I declare __get for read-only properties?

2005-04-04 Thread C Drozdowski
Howdy,
I'd like to access some of the private members of my classes as 
read-only properties without resorting to function calls to access 
them. (e.g. $testClass-privateMember instead of 
$testClass-privateMember(), etc)

Based on my research and testing, using the __get and __set overloading 
methods appears to be the only way to do so. It also, based on testing, 
appears that these private members must be in an array.

What I do not understand is that if I declare a __get method I MUST 
also declare a do nothing __set method to prevent the read-only 
properties from being modified in code that uses the class.

For example, the code below allows me to have read-only properties. 
However, if I remove the do nothing __set method completely, then the 
properties are no longer read-only.

I'm curious as to why I HAVE to implement the __set method?
Example:
?php
class testClass
{
   private $varArray = array('one'='ONE', 'two'='TWO');
   public function __get($name)
   {
   if (array_key_exists($name, $this-varArray)) {
   return $this-varArray[$name];
   }
   }
   public function __set($name, $value)
   {
   }
}
$test = new testClass();
$test-one = 'TWO';   // doesn't work
echo $test-one;  // echo s 'ONE'
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Using header(0 to manage user inactivity

2005-04-03 Thread C Drozdowski
I'd like to be able to timeout a user if they are inactive for X 
minutes. Say, if they walk away from the browser leaving sensivive data 
in plain view.

Is there any reason that using the header() function as below wouldn't 
be a reliable way to do this (albeit user-unfriendly)? It works for 
me on my Mac with various browsers, but I wonder how universally it 
will work.

$timeout = 900;  // 15 minutes
header('Refresh: ' . $timeout . ';url=www.whatever.com/logout.php');
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: mySQL outputting XML

2005-03-25 Thread C Drozdowski
There is a pear package that does this: XML_sql2xml.
It's at:
http://pear.php.net/package-info.php?pacid=18
There is more info at:
http://php.chregu.tv/sql2xml/
It's pretty flexible. But not so complicated that you cannot read 
through the code to figure out what's going on.

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


[PHP] Borrowed code- how to give credit

2005-03-22 Thread C Drozdowski
Hey,
I used a single line of code (ver batim) from a pear class in my own 
code. I try to always be honest and not steal code but this single line 
does exactly what I need. The code is for a NPO website and will never 
be sold or anything like that.

How should I give credit for the line of code in my own code?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] PHP 5 DOM, XPath, UTF-8, and Form Input

2005-03-19 Thread C Drozdowski
I have been doing some testing and need confirmation that the following 
is correct.

You have a DOMDocument that potentially contains UTF-8 encoded data (it 
might not however).

You want to search it via DOMXpath-query() using a value that comes 
from a $_POST value.

If the page that posts the data via a form to the search script  IS NOT 
encoded in UTF-8, then the value must be converted to UTF-8 before it 
is used in the query expression.

Else, if the posting page IS UTF-8 encoded, then the $_POST data does 
not need to be converted before being used in the expression.

Is this correct?
Also, if the $_POST data comes from a UTF-8 encoded page, and it needs 
to be sanitized before use, will the basic PHP string functions work on 
the data (e.g. htmlentities, stripslashes, trim, preg_replace, etc)?

If not what do I have to do?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] XPath Query Exressions and Quote Characters

2005-03-16 Thread C Drozdowski
I've got a problem with quote characters and building XPath query 
expressions (PHP 5.0.3). What do I need to do to get them to work? I've 
tried various encoding functions but cannot figure it out.

Given this expression, if $id contains one or more double quotes, an 
error is thrown.

$query = '//book/chapter' . '[EMAIL PROTECTED]:id=' . $id . ']';
Given this expression, if $id contains one or more single quotes, an 
error is thrown.

$query = //book/[EMAIL PROTECTED]:id='$id'];
I need to be able to build an exression that contains either double or 
single quotes in the search regarding of how I programatically build 
the expression.

Any insight would be appreciated.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: XPath Query Exressions and Quote Characters

2005-03-16 Thread C Drozdowski
It's just a coincidence that I used xml:id as part of my query 
expression. If I use following code method to build my expression:

$query = '//book/chapter[section=' . $section . ']';
or say
$query = '//book/[EMAIL PROTECTED]' . $title . ']';
I get an Invalid Predicate... error when either the $section or 
$title variable contains a double quote.

However, here's an example:
XML:
?xml version=1.0 encoding=UTF-8?
table
   row
   mod_idhome/mod_id
   mod_access1/mod_access
   mod_nameHome/mod_name
   /row
/table
XPath Expression:
$query = '//table/row[mod_name=' . $name . ']';
Variable Assignment:
$name = utf_encode('Home');
Using the expression throws the Invalid Predicate Error.

On 2005-03-16 12:06:24 -0500, [EMAIL PROTECTED] (Jason Barnett) said:
C Drozdowski wrote:
...
$query = '//book/chapter' . '[EMAIL PROTECTED]:id=' . $id . ']';
First of all check the XPath documentation:
http://www.w3.org/TR/xpath
http://www.w3.org/TR/xpath#path-abbrev
AFAIK your expression above is the way to build this query.  Give us a
link to the XML doc if you want us to take a look at that specific doc.
 Also make sure you referenced the correct DTD.  And (just to be sure)
try to validate you document against the DTD.
Given this expression, if $id contains one or more single quotes, an
error is thrown.
$query = //book/[EMAIL PROTECTED]:id='$id'];
I need to be able to build an exression that contains either double or
single quotes in the search regarding of how I programatically build the
expression.
A couple of things that may be in play here...
- First of all I recall there was a specific bug with xml:id, although I
can't recall off the top of my head what it was...
- Secondly the XPath querying interface in PHP will only return simple
data at this point.  In fact, I think it will only return strings.
http://www.w3.org/TR/xpath#attribute-nodes
But if your ID is simple data (integer / string), I can't imagine it
would be a problem for XPath to return it.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php