Re: [PHP] $this -

2004-12-02 Thread Klaus Reimer
R. Van Tassel wrote:
Can someone please point me to the php documentation where it explains
$this -  
1. It must be $this- and not $this - .
2. Documentation can be found here:
http://de.php.net/manual/en/language.oop.php

What is the symbol -  and is $this something only used in classes?
Yes. Inside a method you can use $this to reference the current object 
in which the method was called. The - operator is not specific to 
$this. It is generelly used to call methods or access properties of an 
object.

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


Re: [PHP] PHP 4 to 5 class issues involving static methods and $this

2004-11-17 Thread Klaus Reimer
Chris wrote:
How can I rewrite my class for PHP 5 to emulate the functionality I had 
in  PHP 4 in an error free way?
Have you tried this:
function format_string($string) {
// format the string...
$result = string;
if (isset($this)) $this-elements[] = $result;
return $result;
}
In this form you can check the existance of $this. If you call the 
method statically then $this is not present and the elements array is 
not filled. If you call it non-statically then $this is present and 
elements is filled. The same you can do with show_all().

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


Re: [PHP] my own extension

2004-11-16 Thread Klaus Reimer
Uffe Kousgaard wrote:
If I want to write my own extension for PHP/Linux, is there any
specification on how to do that? Some specific functions that the SO
should always include, call convention etc.?
Those who know don't talk. Those who talk don't know.
It's all in the docs (not much, but enough):
http://www.php.net/manual/en/zend.php

To make things a bit more complex, it will be done with Kylix, so if
anyone has tried that combination before, I would like to hear from
them. But otherwise c++ references are of course OK.
Kylix? Isn't it a Delphi-like language? How do you want to use all the 
include files of PHP which are written for C? Don't you think it's 
easier to use PHP's extension framework? It's pretty easy to use and 
well documented in the Section PHP's Automatic Build System.

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


Re: [PHP] my own extension

2004-11-16 Thread Klaus Reimer
Uffe Kousgaard wrote:
It is a large delphi library I want to call from PHP, so I don't think
it is easier.
But you know your library and you have it under control so maybe it's 
easier to write C include files to interface your Kylix library from C 
instead of writing Delphi-Units to interface PHP from Kylix.

So I would try to first implement a C interface (or C++ if it has OO) 
for your Delphi library and then write a simple PHP extension which uses 
this C/C++ interface to use your delphi lib.

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


Re: [PHP] splitting string

2004-11-16 Thread Klaus Reimer
Afan Pasalic wrote:
But, I can't figure out how to split them back?
$string_back = explode('\n', $string);
That one is the right one. But you must use double quotes, not single 
quotes. Escaped characters (except \') in single quoted strings are not 
processed.

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


[PHP] Overwriting offset methods of ArrayObject

2004-11-14 Thread Klaus Reimer
Hello,
I just tried to overwrite a method of ArrayObject like this:
  class MyArrayObject extends ArrayObject
  {
  public function offsetGet($key)
  {
  echo Here I am\n;
  return parent::offsetGet($key);
  }
  }
  $o = new MyArrayObject();
  $o['test'] = 'test';
  echo $o['test'];
I think this should output the text Here I am because I have 
overwritten the offsetGet method of ArrayObject which is called if I 
access an array element of this object. But it doesn't. My method is 
simply ignored.

Then I've written a simple Object which implements the ArrayAccess 
interface like the ArrayObject object does. And then I have done the 
same as above but this time I don't extend ArrayObject but my own 
object. This works. My overwrite method is called

I'm confused. Why can't I overwrite the method in ArrayObject? Is this a 
bug? Or are the methods of ArrayObject marked as final? But even then 
I must get an Cannot override final method error.

Some hints if I misunderstood something? If not I'm going to file a bug 
report.

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


Re: [PHP] Silly OOP question

2004-11-14 Thread Klaus Reimer
Brent Clements wrote:
or should I
create a projects.class file that has a function called
getProjects.
Yes, that's a possibility. You can even create more stuff in this 
Projects class like createProject, removeProject and stuff like this. If 
 these tasks are pretty static and you don't need multiple instances of 
the Projects class then you can implement it completely statically so 
you don't need to instanciate the class:

class Projects
{
private static $projects = array();
public static function getAll()
{
return self::$projects;
}
public static function add(Project $project)
{
self::$projects[] = $project;
}
}
So now you can do this to get the projects:
  $projects = Projects::getAll();
Adding objects to the list can be done by the constructor of the Project 
class:

function __construct()
{
Projects::add($this);
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Silly OOP question

2004-11-14 Thread Klaus Reimer
Daniel Schierbeck wrote:
you can implement it completely statically so you don't need to 
instanciate the class
Well, it might be useful to have more than one list of projects, ie if 
you want all design-related projects, or all PHP-projects.
But then you might need a class to organize these Project Lists. Maybe 
THIS is then well suited for static methods ;-)

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] Converting a string into ASCII and a bit more - newbie

2004-11-14 Thread Klaus Reimer
Alp wrote:
$x=1
while ($x=strlen($string)) {
$holder = ord(substr($string, $x, 1));
$result = $result . $holder;
}
and failed since it takes ages to process and does not really return a
proper value/result but repetitive number such as 1..
I think you forgot to increment $x. Add an $x++ at the end of your 
loop and it works.

And by the way: It's better to write $result .= $holder if you want to 
append a string to another. That's shorter and (more important) faster.

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


Re: [PHP] Session file not written, session variables messed up.

2004-11-12 Thread Klaus Reimer
Rodolfo wrote:
The weirdness comes when in one frame the script will print Agent Smith
while in the other frame of the same frameset the script which loads on it
will print Thomas Anderson... 
Are both frames loaded at the same time? It's not possible to have two 
concurrently running scripts access the same session at the same time 
(At least when using files as backend). But normally that only means 
that one script execution is delayed until the other script completes or 
closes the session manually. But I never used session.auto_start, I 
always use session_start() in the PHP code. Maybe the auto_start session 
 behaves differently. Maybe you can try disabling auto_start and start 
the session manually. I don't think it make a difference, but who knows. 
 ;-)

On the other hand: Have you checked that your disk has enough room for 
more sessions? Maybe you are working on the bleeding edge of your 
harddisk capacity.

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


Re: [PHP] zip_open + PHP 5

2004-11-11 Thread Klaus Reimer
Nick Halstead wrote:
I have just changed to PHP 5 as I wanted to extend the functionality of one 
of my projects to further use its OO. But I just discovered that one of the 
extensions available under PHP 4+ isnt included in the same way,
The zip_open + other functions are not available under the configure 
options for PHP 5? I know zip is under the PECL and its compilable as an 
extension, but I cant find any documentation on how to include this into 
PHP 5? if its possible at all?
Try this on the command line:
pear install zip
This downloads, compiles and installs the module. Then you need to add 
this line to your php.ini and restart apache:

extension = zip.so
If you are using windows then I can't help you, don't know how it works 
there.

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


Re: [PHP] Multiple session_start()s / Is it a problem??

2004-11-10 Thread Klaus Reimer
Al wrote:
Is there a problem issuing multiple session_start()s for a given script?
I can't find anything in the manual that says one way or the other.
Then you have not looked good enough ;-)

I have some scripts that call more than one functions include file and 
for convenience put a session_start() on each one.
This gives me a Notice error.
You'll find this in the documentation of session_start(): Note:  As of 
PHP 4.3.3, calling session_start() while the session has already been 
started will result in an error of level E_NOTICE. Also, the second 
session start will simply be ignored.

So there is no problem with multiple calls to session_start(). You can 
safely ignore the notice.

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


Re: [PHP] PHP Accelerator

2004-11-09 Thread Klaus Reimer
Adrian Madrid wrote:
I've been running Turck for some time now on PHP5 and haven't had
segfault problems yet. I must say I'm running the latest CVS and using
file sessions (Turck's would give you segfaults). 
I also tried latest CVS and I don't use Turcks cache. Maybe Turck has 
problems with Objects in PHP5 (because there were the great changes) 
while normal Non-OO-Scripts are running flawlessly.

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


Re: [PHP] Arrays

2004-11-09 Thread Klaus Reimer
Zareef Ahmed wrote:
But you need to do serialize and unserialize in case of array or object.
Do ::
$val_ar=array(one,two,three);
$_SESSION['val_ar_store']=serialize($val_ar);
Serialization is done automatically. You don't need to do it yourself. 
You can even store simple value-objects in the session witout manual 
serialization.

So you can do:
$val_ar = array(one, two, three);
$_SESSION['val_ar_store'] = $val_ar;
serialize/unserialize are useful if you want to store complex data in a 
file or in a database.

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


Re: [PHP] PHP Accelerator

2004-11-09 Thread Klaus Reimer
raditha dissanayake wrote:
I am also running turck with php5 without too many problems and that's 
why i recommended it to the OP. However none of the scripts that run on 
it make use of any of the new features of php5.
One example: I'm using osCommerce, which is not using any new 
PHP5-features (It's PHP4 software) but it is using general OO. And the 
results if MMCache is enabled are very unstable. Most of the time the 
HTML output is corrupted. Sometimes it segfaults. These problemse go 
away if I disable MMCache. On PHP4 everything works fine with MMCache.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] Pb'lm of Regular Expression

2004-11-09 Thread Klaus Reimer
[EMAIL PROTECTED] wrote:
thnx for your support every thing is working well 
but 
still one problem, that height and width are not coming so how i modify the
first regular exp. so it shows both height and width.

/img\s+.*?src=(.*?).*?/s

I'm not sure if I understand you. Do you want the complete tag with all 
attributes? The above regex already provides this data in the first 
index of the matches-array. Or do you want to explicitly fetch the width 
and height of an image tag. Then you just need to replace src with 
width or whatever attribute you want in the above regex. You can also 
read multiple attributes with one regex but then you are limited to a 
specific attribute order. So it will not work for pages which are not 
under you control.

A better solution is to do it in multiple steps:
1. Match the complete tag: /img.*?/s
2. Match the attribs in the tag: /(\w+)=(.*?)/s
3. Iterate over the matches of step 2 and search the attribute you need.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] page redirect question

2004-11-09 Thread Klaus Reimer
Victor C. wrote:
Is there anyway to redirect php page other than using
HEADER(LOCATION:URL) ?
Header can only be called if nothing is written to HTML... Is there anyway
around it?
You can use output buffering. Then it doesn't matter where you call 
header(). But if you do a redirect you should clear the output buffer 
before doing so to prevent that the output which has been done so far is 
send to the browser.

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


Re: [PHP] MySQL

2004-11-09 Thread Klaus Reimer
Octavian Rasnita wrote:
Please tell me how to send a null string to be inserted in a MySQL database.
If I do something like:
$string = null;
mysql_query(insert ignore into table(field) values($string));
This will result in the following SQL query:
insert ignore into table(field) values()
If you output a NULL-String then it's just an empty string. That's why 
you get an error. You have to insert the string NULL into your SQL 
statement. But I'm sure you don't want to hardcode this. You want to 
insert a real string if it is set and you want to insert NULL if the 
string is not set, or not? Then you may try this:

mysql_query(sprintf(insert ignore into table (field) values (%s),
  is_null($string) ? NULL : '$string'));

Do I need to addslashes(), or what else?
If the string comes from user input and PHP is not escaping it 
automatically then you want to use this.

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


Re: [PHP] Pb'lm of Regular Expression

2004-11-08 Thread Klaus Reimer
[EMAIL PROTECTED] wrote:
img src=\https://abc.com/first.php?
site_id=abcaid=keyinlid=keyinref=q=\ width=\1\ height=\1\;
/img\s+.*?src=(.*?).*?/s
The complete tag is in index 0, the src is in index 1 of the match-array.

Now what regular expression i write so i can fetch the image tag from my site of
above syntex.And if possible send me the regular expression of fetching 
A href=/A 
/a\s+href=(.*?).*?(.*?)\/a/s
The complete tag is in index 0, the href attrib in index 1 and the link 
text in index 2.

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


Re: [PHP] PHP Accelerator

2004-11-07 Thread Klaus Reimer
raditha dissanayake wrote:
this one:
- Turck MMCache for PHP
Turck MM Cache does not work with PHP 5. It's possible to compile and
load it and some pages are working but most of the time it segfaults.
By the way: Does anybody know if the Turck MM Cache project is still
active? The last change in CVS is 5 months old, the last release is
nearly a year old. And there were rumors that the main developer was
assimilated by Zend.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Downloading Large (100M+) Files

2004-11-04 Thread Klaus Reimer
Robin Getz wrote:
The issue is that readfile writes it to the output buffer before sending 
it to the client. 
Are you sure you HAVE output buffering? What does ob_get_level() return? 
If it returns 0 then you don't have output buffering.

My theory (and it's only a theory) is, that readfile may not be the 
optimal function for this task. Maybe it's implemented to read the whole 
file into memory and then output the data, don't know.

If this theory is true, you may try fpassthru(). The name of this 
function sounds like the file is just passed through which sounds like 
the task you want to perform :-)

The example on php.net of this function is exactly matching your task:
?php
// open the file in a binary mode
$name = .\public\dev\img\ok.png;
$fp = fopen($name, 'rb');
// send the right headers
header(Content-Type: image/png);
header(Content-Length:  . filesize($name));
// dump the picture and stop the script
fpassthru($fp);
exit;
?
--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


[PHP] Shorthand functions (was: Code Snippets' you couldn't live without)

2004-11-04 Thread Klaus Reimer
Murray @ PlanetThoughtful wrote:
with exploring include files to find out what a function does or how a class
operates. I doubt half-a-dozen shorthand functions in that include file
would place a measurable strain on the readability or maintainability of a
project. 
I disagree on that. The problem here is not that the functions are 
short. The problem is, that their names gives absolutely no clue about 
what they are doing. mfr() can be mysql_free_result() but it also can be 
mysql_fetch_row(). So it's not only unreadable, it's also error-prone. 
Sure, it's possible to look up what this function is doing. But is it 
necessary? Everybody (even coders not knowing the mysql functions) can 
understand what mysql_free_result() is doing, without decyphering it 
first.

But I agree that many PHP functions are named too long. But this is 
because they are non-OO functions living without namespaces. So if you 
don't use OO (where you may write something short like $res-free() you 
have to live with that, I fear. Or write shorthand functions, nobody can 
keep you from doing so. I just said, that it is problematic for more 
professional projects where new programmers may begin to work on at any 
time).

And I agree that there are even some very short function names in PHP 
like nl2br(). This looks like a bad naming, but it is not really. nl 
is a well known shorthand for newline. 2 makes clear that it converts 
something. And br is named after the HTML-Tag. So this function name 
GIVES some clues about what it is doing. But for newcomers it may not be 
clear at the beginning what this function is doing. But after a quick 
lookup the newcomer can remember the meaning very well. And I think this 
is different with functions like mfr() and asl() which gives no clue 
about their meaning.


when first viewed by someone new to PHP. Also witness the deprecation of
variables such as $HTTP_GET_VARS in favour of $_GET etc. 
$_GET and $_POST are well named. It's clear what they are doing. Thank 
god their were not named $_HGV and $_HPV.


Or the .=
concatenation assignment operator as a shorthand to $var = $var . ' added
string.' 
$a .= $b is not a shorthand of $a = $a . $b. The result is the same 
but the internal processing is totally different. $a .= $b is a lot 
faster then $a = $a . $b because $b is directly appended to $a. The 
second form constructs a completely new string and overwrites the old 
value of $a. At least this is the case if no optimizer is used. Maybe 
optimizeres are transforming the second form into the first form, don't 
know.

So you can't compare this to a shorthand function. It was not introduced 
because coders are to lazy to write the long form. It was introduced 
because it is absolutely intuitive to do so if the language already has 
something like +=. But I can't tell if these operators were introduced 
into the C programming language (or wherever it appeared first) because 
lazy coders. ;-)


Back to the intent rather than the form of my original question: what are
the code snippets you can't live without?
I already posted some. But this thread is interesting, too. So I changed 
the subject ;-)

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] Sessions and threading

2004-11-04 Thread Klaus Reimer
Devraj Mukherjee wrote:
The first part of the problem is that I need to be able to at all times 
maintain a readable set of objects in memory, I am planning to achieve 
that using session variables, but I hear that session variables can 
become very inefficient, how true is that?
Very true. In Java (with Tomcat for example) you have a real session 
scope and application scope where you can put objects and directly 
access them. These objects are hold in memory and they are REAL objects 
between the requests. In PHP it's different. If a HTTP request is 
finished then the session (with all data including objects) is 
serialized and stored on the harddisk (or database or whatever the 
session backend is). On the next HTTP request the session is loaded from 
harddisk and unserialized. So new objects are created and filled with 
data from the harddisk at every request.

It would be REALLY REALLY cool to have an application-server-like thingy 
in PHP. But as far as I know there is none. Correct me if I'm wrong.


The other issue is running a thread that enable in some time interval to 
write snapshots from the log files that are being generated. Is it 
possible to have part of the script alive in some sort of a thread even 
after the script is dead. For example with the use of the sesssion 
variable.
You can write a command line PHP script and run it as a separate daemon 
or call it from the crontab.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] help in php script

2004-11-04 Thread Klaus Reimer
Deepak Dhake wrote:
But i am not getting any output if i follow the above procedure. Can you 
tell me how to do it? I have to have the script TimeRotateImage.php 
which calculates which image to print accoring to local time and i want 
to embed the file name in html tag to print it on screen.
It's not clear what your PRINT macros are doing. Maybe you forgot to 
send the content-type-header? Or maybe there is a script error which is 
not displayed when you call the page inside a image tag. Call the script 
directly in your browser to see what's going on. If it outputs binary 
data then everything is working but you forgot the content-type header.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] help in php script

2004-11-04 Thread Klaus Reimer
Deepak Dhake wrote:
?PHP
print img src='TimeRotateImage.php';
?
did you get what i am saying? please let me know if you have some solution.
thanks
No. I must admit, It don't understand it. Let me try: You have a script 
a.php which outputs this static content:

img src=b.php
b.php outputs the static content img src=c.jpeg
This can't work. You browser tries to download an image with the name 
'img src=c.jpeg'. I think THAT's your problem and the reason why I 
did not understand you problem. If you use a PHP script inside an img 
src attribute then this PHP-Script must output an image. Complete with 
content-type header and the image as binary data in the body.

Or another solution for a.php:
html
 body
  img src=?php include('b.php')? /
 /body
/html
but I don't see the sense here. You can just do all this in one script:
?php
$curr_time = (localtime());
if ($curr_time[2] = 6 and $curr_time[2] = 17) {
  $img = 'a.jpg';
}
else {
  $img = 'b.jpg';
}
?
html
 body
  img src=?=$img? /
 /body
/html
If I still misunderstood your problem then maybe your description was 
not detailed enough.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] help in php script

2004-11-04 Thread Klaus Reimer
Klaus Reimer wrote:
This can't work. You browser tries to download an image with the name 
'img src=c.jpeg'. 
Ah, I'm talking nonsense. I meant the browser tries to DISPLAY an image 
with the CONTENT 'img src=c.jpeg'. The browser can't do this. 
That's why you don't see anything.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] Downloading Large (100M+) Files

2004-11-04 Thread Klaus Reimer
Robin Getz wrote:
The same problem exists with fpassthru (now that I have let it run a 
little longer) I now have 5 sleeping httpd processes on my system that 
are consuming 200Meg each.
Any thoughts?
Ok, so much for the theory. What about the output buffering? Have you 
checked if you have output buffering enabled? What das ob_get_level() 
return?

If it's activated but you can't find where it is activated then this may 
help to disable it in your script:

while (ob_get_level()) ob_end_flush();
--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] 'Code Snippets' you couldn't live without

2004-11-03 Thread Klaus Reimer
Murray @ PlanetThoughtful wrote:
function asl($val){
function mfr($rset){
This may be ok for private projects but otherwise I don't think it's a 
good idea to create shorthand functions. Other developers (and 
especially new developers beginning to work on the project) are getting 
confused. They must first learn what this functions are doing. The names 
of these functions are not really helpful in understanding what's going on.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] 'Code Snippets' you couldn't live without

2004-11-03 Thread Klaus Reimer
Pablo Gosse wrote:
extra with the results to suit your needs, but as for just using
asl($val) instead of addslashes($val), well why not just extend the PHP
source to make asl() an actual alias to addslashes()?
Extending PHP to have shorthand functions? Was that irony? I hope so. 
Having such shorthand functions directly in PHP might bring us this:

$n = $_I['n'];
$c = mc('localhost');
$d = msd('somedb', $c);
$q = mq(spf('SELECT * FROM users WHERE name='%s', asl($n)), $d);
while ($r = mfa($q)) vd($r);
mfr(q);
Is that really what you want?
--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] 'Code Snippets' you couldn't live without

2004-11-03 Thread Klaus Reimer
Greg Donald wrote:
Murray wasn't asking for your opinions on _his_ code, he was asking
what code _you_ had that you couldn't live without, code that makes
your life easier when reused from project to project.
Ok then. Here comes mine (but not in form of source code. If someone is 
interested, mail me).

I'm doing a lot with dynamic image generation and so I've written a 
gdutils include file containing the following:

imagecolorallocatehex($image, $color) - Allocate a color for an image 
from hexadecimal value. Useful to have the same color syntax for HTML 
and GD output.

imagecolorallocatehexalpha($image, $color, $alpha) - Pretty the same as 
the first function but this time for alpha transparent colors.

imagecreatefromfile($filename) - Checks the image format with 
getimagesize() and loads the image with one of the 
imagecreatefrom(gif|jpeg|png|bmp|xbm) functions.

img_type_to_extension($imgtype, $include_dot = false) - Returns the 
extension for the given image type.

imagettfbbox2($size, $angle, $fontfile, $text, $fix_vertical = false) - 
An improved version of imagettfbbox. Returns correct data (even if 
text is rotated) and also returns more useful data (associative array 
with keys left, right, top, bottom, width and height.

imagecopyresampled2($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, 
$dstH, $srcW, $srcH) - A workaround for the buggy imagecopyresampled. 
The GD library can't really resample images with alphatransparency (see 
bug #29315). So my function passes the GD image to 
ImageMagick/GraphicsMagick (with the imagick module from PECL) which 
resamples the image and passes it back to GD.

And two more functions I'm using regularly:
mkpath($path, $mode) - Create a directory with all parent directories 
and make sure the directory mode is really set (setting umask to 0 
during directory creation)

redirect($url) - Creates a correct url (absolute and with SID if 
needed), sends location header and exits the script.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] Help with preg_match_all()

2004-11-01 Thread Klaus Reimer
Curt Zirzow wrote:
And so on.. It's a kind of a template system... well... I need to
create a expression to get all the tags from the HTML with
preg_match_all() in order to have them in a array...
So your looking from something that starts with '{' and continues
while not a ')' ...
  /{([^}]*?)}/
If you are already using the ? meta character then you can simply do this:
/{(.*?)}/
The while not-approch is useful if you don't want to use the ? meta 
character (to be compatible to regex engines which don't support this). 
But then it would look like this:

/{([^}]*)}/
But all these expressions are to lazy for the required work. The tags 
should be matched more exactly using this:

/{$([\w\.]+)}/
This implies that the variable names always begin with a dollar 
character and they can contain upper and lowercase characters, numbers, 
underscores and periods. The variable name must contain at least one 
character, so {$} is not matched.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] Need to add a 0 to a float number

2004-11-01 Thread Klaus Reimer
Brent Clements wrote:
Solved my own problem
Note to self, RTFM:
number_format is w hat I needed.
Or:
printf(%.2f, $var);
--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] An easier way? $_POST[] = $_SESSION[]

2004-11-01 Thread Klaus Reimer
Erich Kolb wrote:
Is there an easier way to assign all post data from a form to session data?
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['last_name'] = $_POST['last_name'];
$_SESSION['email'] = $_POST['email'];
If a two-dimensional array is ok for you then the easiest way is this:
$_SESSION['user'] = $_POST;
Then you have:
  $_SESSION['user']['first_name'];
  $_SESSION['user']['last_name'];
  $_SESSION['user']['email'];
But you also have something like
  $_SESSION['user']['submit'];
because the submit button in also copied from _POST to the session.
--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] Matching *exact* string?

2004-10-31 Thread Klaus Reimer
Nick Wilson wrote:
How can I alter the above so that only *exact* matches are banned?
Using ^ and $ to mark the begin and end of the line. So try this
/^$ip\$/
--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


[PHP] localeconv

2004-10-30 Thread Klaus Reimer
Hi,
I just noticed an annoying issue with locales in PHP and I'm not sure if 
this behaviour is intended or it's a bug.

I'm doing the following:
setlocale(LC_ALL, 'de_DE');
$l = localeconv();
printf(Decimal point: %s\n, $l['decimal_point']);
printf(Thousands sep: %s\n, $l['thousands_sep']);
This should output a , as decimal point and a . as thousands 
separator but it does only output the standard characters (A dot as 
decimal point and nothing as thousands_sep).

My de_DE locale is properly set up. All other data returned by 
localeconv is correct (EUR currency, Euro currency symbol, monetary 
decimal point and monetary thousand separator and so on). Only the 
decimal_point and thousands_sep is not working.

Also interesting is that printf(%.2f, 123.45) correctly outputs 
123,45. So PHP IS using a comma as decimal point but why does it not 
show up in localeconv()?

I tried exactly the same code in C on the same machine and this is 
working perfectly:

#include locale.h

int main(int argc, char *argv[])
{
struct lconv *l;

setlocale(LC_ALL, de_DE);
l = localeconv();
printf(Decimal point: %s\n, l-decimal_point);
printf(Thousands sep: %s\n, l-thousands_sep);
return 0;
}
This outputs correct german decimal point and thousands separator.
Is there a reason for this misbehaviour of PHP? Or is it a bug? I 
encounter this with PHP 5.0.2 and 4.3.9.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] php compiler

2004-10-30 Thread Klaus Reimer
Hodicska Gergely wrote:
$a = 0;
$b = 1;
if ($a = 1  $b = 0) {
echo 'true ';
var_dump($a);
var_dump($b);
} else {
echo 'false ';
var_dump($a);
var_dump($b);
}
Runing this we get: true bool(false) int(0)
Are you sure you posted the example correctly? It outputs this: false 
bool(false) int(0)

And this output is absolutely correct. Your condition gives new values 
to $a and $b because you use = and not ==. So you do this:

$b = 0;
$a = 1  $b;
The condition checks the value of $a (which is false) and so you land in 
the else branch and that's why $b is int(0) and $a is bool(false)

I think you want this:
if ($a == 1  $b == 0)
--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] php compiler

2004-10-30 Thread Klaus Reimer
Hodicska Gergely wrote:
  It outputs this: false bool(false) int(0)
Yes, this the right output.
And this output is absolutely correct. Your condition gives new values 
to $a and $b because you use = and not ==. So you do this:
Maybe you never read this:
http://hu2.php.net/manual/en/language.operators.php#language.operators.precedence 
The result is not so obvious. There sould some internal behavior which 
cause this.
I don't see the problem. The behaviour of your code matches the
precendences in my opinion:
$a = 1  $b = 0
PHP sees two expressions here:
$a = 1  $b   (because  has higher priority than =)
and
$b = 0;
So the condition resolves to 1  0 while $a is set to false and $b is
set to 0;
So where is the problem?
--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] php compiler

2004-10-30 Thread Klaus Reimer
Hodicska Gergely wrote:
$a = 1  $b = 0
PHP sees two expressions here:
After the precedence table the first thing should be evaluating 1  $b, 
so we get:
$a = false = 0
Which is not meaningful thing, and maybe this cause that the evaluating 
of the statment is not in the right order.
= has a right  associativity. This is well explained on the page you 
think I have not read. See Example 15-1. $b = 0 is evaluated first and 
the 1  $b is evaluated after that.

Everything else would make no sense. (1  $b) = 0 is not a valid 
expression and throws an error.

--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


Re: [PHP] php compiler

2004-10-30 Thread Klaus Reimer
Hodicska Gergely wrote:
Oke, but  has a higher precedence. The right  associativity has 
sense when all the operand has the same precedence.
I think the precedence of left and right associative operands can't be 
compared. The switch between associativities already separates the 
expression (if it could be explained this way). So you have to handle 
left-evaluated expressions and right-evaluated expressions 
separately. That's why $b = 0 and 1  $b are evaluated separately.

The PHP manual gives a fine example: Note:  Although ! has a higher 
precedence than =, PHP will still allow expressions similar to the 
following: if (!$a = foo()), in which case the output from foo() is put 
into $a.

And that's because = is right and ! is non-associative.
--
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)


signature.asc
Description: OpenPGP digital signature


[PHP] imagecopyresampled()

2004-06-29 Thread Klaus Reimer
Hello,

I have a problem with imagecopyresampled() and I'm not sure if this is a bug 
in GD or PHP or it's a feature. I'm trying to do the following (This example 
doesn't make much sense, it's just a simple way to reproduce the problem):

I have an alphatransparent image 512x512. I want to resample that image to 
256x256 and draw it onto a blue background. After that I want the background 
color to be pixel-transparent.

With GD I'm doing it like that:

1. Create new true color image with a size of 255x255
2. Allocate a background color and fill the new image
3. Load the alphatransparent PNG
4. Render the PNG on the background image with imagecopyresampled
5. Define the background color as transparent (imagecolortransparent)
6. Save the image as PNG.

Now here is the result:

http://www.ailis.de/~k/test/imagecopyresampled/255.png

If I do exactly the same with a target image size which is a base of 2 (2, 4, 
8, 16,  256) it works. See here:

http://www.ailis.de/~k/test/imagecopyresampled/256.png


With imagecopyresized everything works fine. But imagecopyresampled has 
problems with binary uneven target sizes. Is this a GD bug? I'm using PHP 
4.3.3 with GD 2.0.23 (The stuff from current Debian Sarge). Does anybody know 
a solution or a workaround?

-- 
Bye, K http://www.ailis.de/~k/ (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)

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