[PHP] Re: Please tell me I dont know regex

2006-09-16 Thread Tom Atkinson

See http://uk.php.net/manual/en/function.eregi.php#57824

Basically you don't need to escape the dash, just place it somewhere 
where it cannot be interpreted as indicating a range. It will then be 
treated literally.


They do work the same using preg_match() which requires escaping.


william(at)elan.net wrote:


Please try below page/program on your system entering "ab-cd" and
please tell me I dont know regex - because the way I see it the
results of those tests should have been the same...

---


Please enter something with a dash here: 
name='regex_test' />



  if (ereg("^[A-Za-z0-9\._\-]{3,63}$",$_REQUEST['regex_test'])) print " 
Ok";

  else print " Nak";
 print "";
 print "Testing ".$_REQUEST['regex_test'].' with regex 
/^[A-Za-z0-9\.\-_]{3,63}$/ ... :';
  if (ereg("^[A-Za-z0-9\.\-_]{3,63}$",$_REQUEST['regex_test'])) print " 
Ok";

  else print " Nak";
}
print "Current PHP Version is: ".phpversion();
?>




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



[PHP] Re: php and session issues continued...

2006-09-16 Thread Tom Atkinson

How are you setting the location?

If the user starts at www.yoursite.com and you redirect to yoursite.com 
after the first form then you'll lose the session since it's a different 
domain.




Dave Goodchild wrote:

Hi all. I have a session issue and wondered if anyone else has encountered
this:

I have an app where a user fills out 3 forms. In each case, after 
validation

and cleaning the form data is passed into session variables and after the
final submission the data is entered into the database. I am using both
Firefox and IE6 on Windows XP and the system works like a dream. However, a
user testing on IE6/XP is having some problems. The values from the first
form are not being passed into the session.

When each form is successfully processed the user is redirected to the next
stage using header('Location...'). I call session_write_close before 
that to

ensure the session data is written out before the redirect, but the problem
persists.

Anyone recognise this issue. It is not IE-specific as it happens to me on
Firefox intermittently. I am at my wits end! Thanks in advance for any 
help!




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



[PHP] Re: DOMDocument->saveXML()

2006-09-18 Thread Tom Atkinson

Pass the root node of your tree as a parameter to saveXML()

Chris Boget wrote:
I looked all through the documentation but was unable to find out if 
this was possible and, if so, how.  When you call ->saveXML(), it prints 
out the XML declaration  alont with the structure 
of the document.  Is there any way to suppress that?  I'm trying to 
print out extra text (in the form of a stylesheet call) and the 
declaration that ->saveXML() prints out is messing everything up.


Would it be possible to point to the relevant page in the documentation 
that discusses how to do this?


thnx,
Chris


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



Re: [PHP] DOMDocument->saveXML()

2006-09-18 Thread Tom Atkinson

Perhaps you missed my reply.

http://www.php.net/manual/en/function.dom-domdocument-savexml.php

The first parameter to DOMDocument->saveXML() is described:

"Use this parameter to output only a specific node without XML 
declaration rather than the entire document."


If you pass the root node then you get the entire document without the 
XML declaration.


That's both elegant and built-in.

Tom.

Chris Boget wrote:

Would it be possible to point to the relevant page in the
documentation that discusses how to do this?

If there is nothing builtin to do it, how tricky could it be to strip
off the first line after you saved it?...


Not tricky at all.


"Crude, but effective, Captain" -- Spock


Exactly.  I was just hoping for something a bit more elegant.
Hopefully using something that was built in to DOMDocument.
Oh, well.

thnx,
Chris


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



[PHP] Re: FTP Copy

2006-09-19 Thread Tom Atkinson

ftp_rename() should be able do that

Matt Palermo wrote:
I've been looking on php.net, but can't find anything that covers this... 
Basically, I am using PHP FTP to connect to an FTP server and run some 
functions.  I want to copy a directory on the FTP server to another 
directory on the FTP server.  Since there isn't an ftp_copy() function, I 
have to use ftp_get() to bring the file to the local webserver temp folder, 
then use ftp_put() to place it into a different folder on the FTP server. 
This is quite a big pain, since the webserver is not on the same network as 
the remote FTP server, so it must download the file and then upload it to a 
different place (takes a long time).  Is there an FTP that will just copy 
the file/folder from the FTP server without the need to download/upload it 
somewhere else?


Thanks,

Matt 


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



[PHP] Help converting C to PHP

2006-09-21 Thread Tom Atkinson

Hello,

I am attempting to convert this code for generating the digits of pi 
from the original C (below) to PHP.


 long k=4e3,p,a[337],q,t=1e3;
  main(j){for(;a[j=q=0]+=2,--k;)
  for(p=1+2*k;j<337;q=a[j]*k+q%p*t,a[j++]=q/p)
  k!=j>2?:printf("%.3d",a[j-2]%t+q/p/t);}

I converted this to a more readable form:

long k=4e3;
int p;
int a[337];
int q;
int t=1e3;

main(j){
  for(;a[j=q=0]+=2,--k;){
for(p=1+(2*k);j<337;q=(a[j]*k)+((q%p)*t),a[j++]=(q/p)){
  if (j>2 && k==1) printf("%.3d",(a[j-2]%t)+((q/p)/t));
}
  }
}

and then changed it to PHP syntax

$k=4e3;
$p=0;
$a=array();
$q=0;
$t=1e3;

for(;$a[$j=$q=0]+=2,--$k;){
  for($p=1+(2*$k);$j<337;$q=($a[$j]*$k)+(($q%$p)*$t),$a[$j++]=($q/$p)){
if ($j>2 && $k==1) printf("%.3d",($a[$j-2]%$t)+(($q/$p)/$t));
  }
}

The C code correctly gives me pi, but the PHP code gives me some other 
number which is not pi.


What am I missing?

Tom.

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



Re: [PHP] Help converting C to PHP

2006-09-21 Thread Tom Atkinson

Yes, it is.

Kevin Waterson wrote:

This one time, at band camp, Tom Atkinson <[EMAIL PROTECTED]> wrote:


Hello,

I am attempting to convert this code for generating the digits of pi 
from the original C (below) to PHP.


is this for codegolf?

Kevin



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



Re: [PHP] Help converting C to PHP

2006-09-21 Thread Tom Atkinson

pi() does not give me enough decimal places, I need the first 1000.

Curt Zirzow wrote:

On 9/21/06, Tom Atkinson <[EMAIL PROTECTED]> wrote:

Hello,

I am attempting to convert this code for generating the digits of pi
from the original C (below) to PHP.

  long k=4e3,p,a[337],q,t=1e3;
   main(j){for(;a[j=q=0]+=2,--k;)
   for(p=1+2*k;j<337;q=a[j]*k+q%p*t,a[j++]=q/p)
   k!=j>2?:printf("%.3d",a[j-2]%t+q/p/t);}



wow this is rather bad. it would probably be better to write this in
asm, it would be easier to read than the way it is in C.



I converted this to a more readable form:


what about using:
 php.net/pi

note the precision description.

or are we talking about a different pi.


Curt.


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



[PHP] Re: Help converting C to PHP

2006-09-21 Thread Tom Atkinson


I have solved the problem. The variables are declared as and forced to 
remain integers in C but PHP converts them to float during division. 
This messed up the maths. Also there was a slight difference in 
formatting for printf().



Tom Atkinson wrote:

Hello,

I am attempting to convert this code for generating the digits of pi 
from the original C (below) to PHP.


 long k=4e3,p,a[337],q,t=1e3;
  main(j){for(;a[j=q=0]+=2,--k;)
  for(p=1+2*k;j<337;q=a[j]*k+q%p*t,a[j++]=q/p)
  k!=j>2?:printf("%.3d",a[j-2]%t+q/p/t);}

I converted this to a more readable form:

long k=4e3;
int p;
int a[337];
int q;
int t=1e3;

main(j){
  for(;a[j=q=0]+=2,--k;){
for(p=1+(2*k);j<337;q=(a[j]*k)+((q%p)*t),a[j++]=(q/p)){
  if (j>2 && k==1) printf("%.3d",(a[j-2]%t)+((q/p)/t));
}
  }
}

and then changed it to PHP syntax

$k=4e3;
$p=0;
$a=array();
$q=0;
$t=1e3;

for(;$a[$j=$q=0]+=2,--$k;){
  for($p=1+(2*$k);$j<337;$q=($a[$j]*$k)+(($q%$p)*$t),$a[$j++]=($q/$p)){
if ($j>2 && $k==1) printf("%.3d",($a[$j-2]%$t)+(($q/$p)/$t));
  }
}

The C code correctly gives me pi, but the PHP code gives me some other 
number which is not pi.


What am I missing?

Tom.


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



Re: [PHP] Help converting C to PHP

2006-09-22 Thread Tom Atkinson

Martin Alterisio wrote:

2006/9/22, Rory Browne <[EMAIL PROTECTED]>:


On 9/22/06, Kevin Waterson <[EMAIL PROTECTED]> wrote:
>
> This one time, at band camp, "Curt Zirzow" <[EMAIL PROTECTED]> wrote:
>
> > what about using:
> >   php.net/pi
> >
> > note the precision description.
> >
> > or are we talking about a different pi.
>
> The goal of the codegolf.com challenge is to print pi to 1000 places.
> The programmer to do it in the least keystrokes is the winner.


I personally don't think this is a very healthy contest. It discourages
comments, and use of whitespace to make code readable.

I'd perfer a contest that rewarded code readability, and maintainability
as
well as minimal keystrokes. After all you only enter the aforementioned
keystrokes once. Perhaps one like codegolf, with an enforced coding style
(
eg KR Style, or GNU Style)



I completely agree. This kind of contests do not provide any measure of the
good qualities of a programmer working as part of a team. The objectives
ussualy end up being something of the sort: "let's see who can fit the most
in a for declaration".

Anyway... as you say, it would be nice to have a contest that rewards
readability and maintainability... but, how can we messure that 
qualities in

this type of games? Should your code be praised by others and voted on? Is
that reliable? I think enforcing a coding style is too restrictive... Also,
how do we measure the declarativity of var and function names?



The value of these games is that they give you interesting problems to 
solve without forcing you to maintain the code. That's the entire point. 
It's exactly the sort of thing that's fun to write when you have to make 
a living from your code the rest of the time. If you want to write 
quality software in your free time then you start/join an FOSS project 
and put the code to good use.


Nobody is claiming that this is a good way to write code or a good way 
to learn PHP, it's just for fun.


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



Re: [PHP] libcurl (cookies across cURL session). . .?

2006-09-23 Thread Tom Atkinson

Use cURL's own cookie handling features.

curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');

That will store the cookies in the file and read them from there next 
time. /tmp may or may not be a suitable location.


Michael Williams wrote:

Robert,

Thanks.  The thing is that lots of cookies are set regularly.  Are you 
suggesting that every time I receive a "Set-Cookie:" to  1)parse that 
line out 2)append it to a file 3) retrieve it when necessary?  I'm not 
terribly familiar with the proper format for a cookie, but I'll look 
into it.  I'd appreciate *any* insights you have.


Regards,
Mike

On Sep 23, 2006, at 2:28 AM, Robert Cummings wrote:


On Sat, 2006-09-23 at 02:10 -0400, Michael Williams wrote:

Hi all,

Is there any way at all by which to persist cookies across cURL
sessions?  Basically I have a login page that sets cookies and looks
for them for "logged in" status so that the user may use the site to
their heart's content.  The problem with cURL, however, appears that
after the initial login, any further attempts are foiled by the fact
that the cookies don't remain.  How exactly should I go about doing
this?


You should be able to retrieve the cookies from the response headers.
Then you just need to resend them. There may be an option for cURL to do
this automatically. Search for cookie at the following link (check the
user comments also):

http://ca.php.net/manual/en/ref.curl.php

Cheers,
Rob.
--..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'





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



[PHP] Re: Is there such a thing?

2006-10-27 Thread Tom Atkinson

http://gtk.php.net/

Integz wrote:

http://www.evilbitz.com/2006/10/27/local-php-standalone-binaries-2/



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



[PHP] Re: How do I get ini_set('output_handler', '') to work?!

2006-10-27 Thread Tom Atkinson
You can't test it like that. When you use system('php') you invoke a new 
instance of php that has the default values. You are apparently already 
familiar with ini_set() so why not use ini_get() to test if your code works?


Daevid Vincent wrote:

What am I doing wrong...

In my php.ini I have this for my web pages (and I want it): 


  output_handler = ob_gzhandler

But this causes my command line script to not show output until the very
end.

I thought I could disable it at the top of a script, but it's not working!?!

#!/usr/bin/php -q
  ini_set('output_handler', 'mb_output_handler'); 
  system('php -i | grep output_handler');

?>

[EMAIL PROTECTED] ./myscript.php
output_handler => ob_gzhandler => ob_gzhandler
zlib.output_handler => no value => no value


If I comment out the line in the php.ini file, then things work great (and
what exactly is the output_handler being used if I don't specify one? It
just says 


  output_handler => no value => no value

I tried to put this in my script too but it doesn't make any difference:

  ini_set('output_handler', ''); 
or
  ini_set('output_handler', null); 


[EMAIL PROTECTED] ./myscript.php
output_handler => ob_gzhandler => ob_gzhandler
zlib.output_handler => no value => no value

UGH!


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



Re: [PHP] in_array() related problem

2006-11-04 Thread Tom Atkinson

Try like this:

var_dump(in_array($a, $test, true));


Richard Lynch wrote:

Try providing a custom comparison function.

Almost for sure, PHP is attempting to "test" the == by a deeper scan
than you think.

On Fri, November 3, 2006 10:56 am, tamcy wrote:

Hello all,

I'm new to this list. To not flooding the bug tracking system I hope
to clarify some of my understanding here.

I am referring to the (now bogus) bug report
http://bugs.php.net/bug.php?id=39356&edit=2. This happens after my
upgrade to PHP 5.2, where the code shown produces a "Fatal error:
Nesting level too deep - recursive dependency?". Same testing code
reproduced below:


a = $a;
$a->b = $b;

$test = array($a, $b);

var_dump(in_array($a, $test));


I think this is not rare for a child item to have knowledge about its
parent, forming a cross-reference.

This code runs with no problem in PHP5.1.6, but not in 5.2. Ilia
kindly points out that "In php 5 objects are passed by reference, so
your code does in
fact create a circular dependency.". I know the passed by reference
rule. What I'm now puzzled is, why this should lead to an error.

To my knowledge, despite the type-casting issue and actual algorithm,
in_array() should actually do nothing more than:

function mimic_in_array($search, $list)
{
  foreach ($list as $item)
if ($search == $item)
  return true;
  return false;
}

Which means:
1. in_array() isn't multi-dimensional.
2. in_array() doesn't care about the properties of any object.

That is, I don't expect in_array() to nest through all available inner
arrays for a match, not to mention those are object properties, not
arrays.

So here is the question: Why should in_array() throws such a "Fatal
error: Nesting level too deep" error? Why should it care? Is there any
behaviour I don't know?

Thanks all in advance.

Tamcy

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







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