Re: [PHP] bit wise math? Is there a function to easily return the bits?

2007-01-26 Thread Satyam

pre?php
$n = 7;

for ($i = 1; $i $n;$i =1) if ($i  $n) $a[] = $i; // 
put it in an array or do whatever, $i contains the parts.


var_dump($a);
?
/pre


- Original Message - 
From: Richard Lynch [EMAIL PROTECTED]

To: Jon Anderson [EMAIL PROTECTED]
Cc: blackwater dev [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Friday, January 26, 2007 12:29 AM
Subject: Re: [PHP] bit wise math? Is there a function to easily return the 
bits?




On Thu, January 25, 2007 1:34 pm, Jon Anderson wrote:

function bits($num) {
$bit_array = str_split(strrev(decbin(intval($num;
$val_array = array();
foreach ($bit_array as $pow = $bit) {
if ($val = $bit * pow(2,$pow))
$val_array[] = $val;
}
return($val_array);
}

(I wanted to see if I could write it in few LOC.) I wonder if there's
a
faster way...


//these might be marginally faster...
function bits($num){
 $bits = array();
 $bin = decbin(intval($num));
 $v = 1;
 for ($b = strlen($bin) - 1; $b = 0; $b--){
   if ($bin[$b] === '1') $bits[] = $v;
   $v = $v * 2;
 }
 return $bits;
}


function bits($num){
 $num = (int) $num;
 $v = 1;
 $bits = array();
 while ($v = $num){
   if ($v  $num) $bits[] = $v;
   $v = $v * 2;
 }
 return $bits;
}

I suspect there is a much faster way, somewhere, somehow...



jon

blackwater dev wrote:

Is there a php function I can call to pass in a number and get the
values
returned?

For example, pass in 7 and get 1,2,4 ?

Thanks!



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





--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--
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



Re: [PHP] Send Email to Mobiles

2007-01-26 Thread clive

Marcelo Ferrufino Murillo wrote:
Hi guys, I need to send a email to mobiles I don´t know if I have to use 
the

function mail( ) or if I have to use other one. Thanks your help



if your intention is to send the mobile phone a sms, then you are going 
to have to use a gateway company of sorts, in SA we have a few and they 
provide a number of interfaces: some to email to sms, some have a http 
api. Ive also seen ftp api, but those are for bulk sms'ing.


clive

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



Re: [PHP] Re: php from address

2007-01-26 Thread Chantal Rosmuller
On Thursday 25 January 2007 18:51, M.Sokolewicz wrote:
 Chantal Rosmuller wrote:
  Hi everyone,
 
  In November I sent a mail to this list asking how to get the mail From
  header right, I solved that but I still have a problem. The solution was
  using the -f option like this:
 
  $frommail = [EMAIL PROTECTED];
  mail($to, $subject, $message, $headers,-f$frommail);
 
  The from address is correct now but the displayed name is still www-data
  (or apache, depends on the server configuration). The header looks like
  this:
 
  From: [EMAIL PROTECTED] (www-data)
 
  Is there anyway to change this?
  Thanks, regards Chantal

 $frommail = [EMAIL PROTECTED];
 mail($to, $subject, $message, $headers,-f$frommail);

 is an extremely ugly way to pass variables IMO.
 $frommail = [EMAIL PROTECTED];
 mail($to, $subject, $message, $headers, -f.$frommail);

 is a lot nicer IMO. Anyway, to get back to you. The name you want
 would be supplied by having the header
 From: [EMAIL PROTECTED]
 in the following format:
 From: MyName Goes Here [EMAIL PROTECTED]

Okay that works! Thanks a lot.

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



[PHP] PHP 5.2.0 + qmail problem

2007-01-26 Thread Bc. Radek Krejca
Hello,

  I had to change my mailserver from sendmail to qmail. After it I saw
  that the mail generated by function mail() has 2 newlines in body except 1.
  I have this konfiguration on server with php4xx and no problem is
  there. Also if I change back sendmail so it is working too.

  The output with this problem is:
--
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
X-Qmail-Scanner-1.25: added fake MIME-Version header
MIME-Version: 1.0

SVA6IDEwLjQuMjQuMjQyClRhcmlmOiBBS0NFIC0gSU5URVJORVQgMTAyNDAvMTAyNDAgLSAyMDQ4

TUIgRlVQIDM4NApVxb5pdmF0ZWw6IEphbiBMVUvDgcWgCkZpcm1hOiBKYW4gTFVLw4HFoApBZHJl

c2E6IEouQmVuZHkgMjgKMzcwIDA1IMSMZXNrw6kgQnVkxJtqb3ZpY2UKQnJhbmE6IDEyCkJvZDog
--

but should be
--
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
X-Qmail-Scanner-1.25: added fake MIME-Version header
MIME-Version: 1.0

SVA6IDEwLjQuMjQuMjQyClRhcmlmOiBBS0NFIC0gSU5URVJORVQgMTAyNDAvMTAyNDAgLSAyMDQ4
TUIgRlVQIDM4NApVxb5pdmF0ZWw6IEphbiBMVUvDgcWgCkZpcm1hOiBKYW4gTFVLw4HFoApBZHJl
c2E6IEouQmVuZHkgMjgKMzcwIDA1IMSMZXNrw6kgQnVkxJtqb3ZpY2UKQnJhbmE6IDEyCkJvZDog
--

  It makes me problem if I use Content-Transfer-Encoding: 8bit.

  My idea is that qmail doesn't trim body of message and newer PHP
  too bud I don't know if I am right.

  Where could be a problem?

-- 
S pozdravem,
 Bc. Radek Krejca
 ICQ: 65895541 

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



[PHP] Ongoing encoding issues

2007-01-26 Thread Dave Goodchild

Hi all, I posted a question a couple of days ago regarding a web app I have
wherein users are able to indicated prices and concessions via a text field,
and the resulting encoding issues I have experienced, the main one being
seeing the pound sign as £ if viewing the results in a browser with the
encoding set to Latin-1.

My question is, how do I overcome this. If I set my browser encoding to
Latin-1 and enter the data I get that odd symbol, if I set it to UTF-8 I get
clean data. Is there a way to sniff out what encoding the browser is using
and then clean the data in any way.

I am googling for help also but you guys have been so helpful in the past I
thought I'd try you also.

--
http://www.web-buddha.co.uk


[PHP] php javascript interaction

2007-01-26 Thread William Stokes
Hello,

I need some advice on how to learn Javascript and PHP interaction. Any good 
tutorials on the web would be most welcome. I particulary need to learn how 
to pass JS user input/choices to PHP.

My current problem is how to ask user confirmation over his actions on a web 
form after POST. Are you sure type questions and how to pass the user 
choice back to program make choices with PHP.

Thanks
-Will

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



[PHP] two php.ini on the same server

2007-01-26 Thread phpdevster

Hi

i am trying to run two Apache server on the same machine and that is work
fine

but the problem is how to create separate php.ini for each Apache server .
is that possible ??


Re: [PHP] Ongoing encoding issues

2007-01-26 Thread Jochem Maas
Dave Goodchild wrote:
 Hi all, I posted a question a couple of days ago regarding a web app I have
 wherein users are able to indicated prices and concessions via a text
 field,
 and the resulting encoding issues I have experienced, the main one being
 seeing the pound sign as £ if viewing the results in a browser with the
 encoding set to Latin-1.
 
 My question is, how do I overcome this. If I set my browser encoding to
 Latin-1 and enter the data I get that odd symbol, if I set it to UTF-8 I
 get
 clean data. Is there a way to sniff out what encoding the browser is using
 and then clean the data in any way.

check out phpinfo(); there is stuff in there telling you about what client
encoding was [probably] used.

that said you should probably opt to output everything as UTF-8 - all decent
browsers will return data in the same encoding as the page was given to them in
by default - this requires you to have php send the correct header (don't
bother with all that META tag crap), doing the following will automatically 
cause
the appropriate header to be sent:

ini_set('output_encoding', 'UTF-8');

 
 I am googling for help also but you guys have been so helpful in the past I
 thought I'd try you also.
 

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



[PHP] Re: two php.ini on the same server

2007-01-26 Thread Colin Guthrie
phpdevster wrote:
 Hi
 
 i am trying to run two Apache server on the same machine and that is work
 fine
 
 but the problem is how to create separate php.ini for each Apache server .
 is that possible ??

It would be easy to do with a chrooted setup, but I'm sure there are
other ways too.

Also, depending on what differences you need to make, you can perhaps
use the apache directives php_value and php_flag etc. to override the
necessary php.ini settings for your second httpd. This would not always
work tho' (for example if you need to tweak the enabled extensions etc.).

This will also only work if you are using PHP as a module, and not as CGI.

Col.

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



Re: [PHP] Ongoing encoding issues

2007-01-26 Thread Frank Arensmeier

Hi Dave.

I don't think you are able to detect your users character encoding  
with php only (at least not rock-solid). Just some days ago, there  
was a discussion about that issue (at least concerning Safari) on the  
Apple web dev mailing list.


Have a look at:
http://lists.apple.com/archives/web-dev/2007/Jan/msg00038.html

I could be possible to send some information about character encoding  
along with the user submitted post data to your php script as well.  
Depending on that encoding, do some string replace on your input data.


Have you provided a valid charset encoding in your html?

Maybe you could give us a link to a test page?

//frank

26 jan 2007 kl. 10.33 skrev Dave Goodchild:

Hi all, I posted a question a couple of days ago regarding a web  
app I have
wherein users are able to indicated prices and concessions via a  
text field,
and the resulting encoding issues I have experienced, the main one  
being
seeing the pound sign as £ if viewing the results in a browser  
with the

encoding set to Latin-1.

My question is, how do I overcome this. If I set my browser  
encoding to
Latin-1 and enter the data I get that odd symbol, if I set it to  
UTF-8 I get
clean data. Is there a way to sniff out what encoding the browser  
is using

and then clean the data in any way.

I am googling for help also but you guys have been so helpful in  
the past I

thought I'd try you also.

--
http://www.web-buddha.co.uk


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



Re: [PHP] bit wise math? Is there a function to easily return the bits?

2007-01-26 Thread Satyam


- Original Message - 
From: Satyam [EMAIL PROTECTED]




pre?php
$n = 7;

for ($i = 1; $i $n;$i =1) if ($i  $n) $a[] = $i; 
// put it in an array or do whatever, $i contains the parts.





Sorry, the above fails for numbers which are powers of two, it should have 
been:


for ($i = 1; $i =  $n;$i =1) if ($i  $n) echo $ibr /;

(Notice less than or equal in the while part)

Satyam




var_dump($a);
?
/pre


- Original Message - 
From: Richard Lynch [EMAIL PROTECTED]

To: Jon Anderson [EMAIL PROTECTED]
Cc: blackwater dev [EMAIL PROTECTED]; 
php-general@lists.php.net

Sent: Friday, January 26, 2007 12:29 AM
Subject: Re: [PHP] bit wise math? Is there a function to easily return the 
bits?




On Thu, January 25, 2007 1:34 pm, Jon Anderson wrote:

function bits($num) {
$bit_array = str_split(strrev(decbin(intval($num;
$val_array = array();
foreach ($bit_array as $pow = $bit) {
if ($val = $bit * pow(2,$pow))
$val_array[] = $val;
}
return($val_array);
}

(I wanted to see if I could write it in few LOC.) I wonder if there's
a
faster way...


//these might be marginally faster...
function bits($num){
 $bits = array();
 $bin = decbin(intval($num));
 $v = 1;
 for ($b = strlen($bin) - 1; $b = 0; $b--){
   if ($bin[$b] === '1') $bits[] = $v;
   $v = $v * 2;
 }
 return $bits;
}


function bits($num){
 $num = (int) $num;
 $v = 1;
 $bits = array();
 while ($v = $num){
   if ($v  $num) $bits[] = $v;
   $v = $v * 2;
 }
 return $bits;
}

I suspect there is a much faster way, somewhere, somehow...



jon

blackwater dev wrote:

Is there a php function I can call to pass in a number and get the
values
returned?

For example, pass in 7 and get 1,2,4 ?

Thanks!



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





--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--
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



Re: [PHP] Ongoing encoding issues

2007-01-26 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-01-26 14:29:52 +0100:
 I don't think you are able to detect your users character encoding  
 with php only (at least not rock-solid). Just some days ago, there  
 was a discussion about that issue (at least concerning Safari) on the  
 Apple web dev mailing list.
 
 Have a look at:
 http://lists.apple.com/archives/web-dev/2007/Jan/msg00038.html

That thread is about a different problem.
 
 I could be possible to send some information about character encoding  
 along with the user submitted post data to your php script as well.  

Yeah, it's called the Content-Type entity header, and it's an important
part of HTTP... Have you heard about HTTP?

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



[PHP] Re: two php.ini on the same server

2007-01-26 Thread zerof

phpdevster escreveu:

Hi

i am trying to run two Apache server on the same machine and that is work
fine

but the problem is how to create separate php.ini for each Apache server .
is that possible ??


Two usual possibilities:

1) To install two Apache Services ( Windows environment )

   Apache 1.3.xx running php 4
   Apache 2 running php 5

   http://www.educar.pro.br/

2) To use only one Apache2 Service

   Setting two virtual hosts, one for php4 and other for php5

   http://foundationphp.com/tutorials/apache22_vhosts.php
--
zerof
http://www.educar.pro.br/
Apache - PHP - MySQL - Boolean Logics - Project Management
--
Você deve, sempre, consultar uma segunda opinião!
--  
You must hear, always, one second opinion! In all cases.
--
Let the people know if this info was useful to you!
--

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



Re: [PHP] retrieve all the groups a user is memberOf from active directory?

2007-01-26 Thread Bing Du
 On Thu, January 25, 2007 3:07 pm, Bing Du wrote:
 Sorry if the top is not closely PHP related.  But I need to accomplish
 it
 using PHP.

 I can query the attribute 'memberOf' of a user from the active
 directory
 server with no problem.  The challenge I'm facing now is how to obtain
 all
 the groups a user is member of.  In many cases, a user can be in many
 groups which could be nested.  Say, user is a member of group B which
 is a
 member of group A.  So user should be member of group A implicitly.
 But
 in active directory, user's account only has

 memberOf:  CN=Group_B,OU=security
 groups,OU=Users,OU=Coll,DC=some,DC=edu

 I can then check if Group_B's LDAP entry has any 'memberOf' attribute,
 so
 on and so on.  If user's LDAP entry has multiple 'memberOf'
 attributes, I
 have to check each one to see if each group has any parent groups.
 Anybody ever had to deal with such a kind of issue and would like to
 shed
 some light (better with some code samples) how it should be done
 effectively?  Any ideas would be greatly appreciated.

 I don't know hardly anything about LDAP, and even less about Active
 Directory, but if you can't find a built-in function to do this and
 have to write your own, it should end up looking something like:

 function groups($user, $groups = null){
   //very first time, initialize $groups to empty array:
   if (is_null($groups)) $groups = array();

   //Find all the groups that his user/group is a memberOf:
   $member_of = //do your LDAP here to find the memberOf:
   //ex: CN=Group_B,OU=security groups,OU=Users,OU=Coll,DC=some,DC=edu

   //Look at each group in turn
   $member_of = explode(',', $member_of);
   foreach($member_of as $group){
 //Skip any groups we have already seen:
 if (isset($groups[$group])) continue;

 //Add it to the list of groups:
 $groups[$group] = $group;

 //check for super-groups of this group:
 $groups = array_merge($groups, groups($group, $groups));
   }
 }

Excellent!  Thanks much for the quick response.  Appreciate it.  I see the
general logic is right.

Bing

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



[PHP] php code to upload a url correctly

2007-01-26 Thread Corden James (RW3) CMMC Manchester
I have a form in which users submit a url. I am having problems as some
people submit the url in the format http://www.blah.blah.org
http://www.blah.blah.org/  while others submit in the format
www.blah.blah.org http://www.blah.blah.org/  I have designed the form
so that it seems fairly obvious (to me anyway) not to include the
http:// but people are still doing it (presumably because they are
copying and pasting from a browser). My form processing script is
designed to add http:// to the submitted url and place the modified url
in a database for future use. As you can imagine sometimes I end up with
urls such as http://http://www.blah.blah.org
http://http:/www.blah.blah.org  in my database. Hence I need a more
rigorous form processing script that is capable of first checking if the
url includes http:// and then processes accordingly. Can anyone point me
in the right direction for such a script?

 

Thanks

 

Dr James Corden

Technology Evaluation Manager

TrusTECH, Innovation Unit

1st Floor Postgraduate Centre

Manchester Royal Infirmary

Oxford Road

Manchester 

M13 9WL

 

Tel:   0161 276 5782

Fax:  0161 276 5766

E-mail: [EMAIL PROTECTED]

Web: http://www.trustech.org.uk

This email and any files transmitted with it are confidential and solely
for the use of the intended recipient. It may contain material protected
by law as a legally privileged document and copyright work. Its content
should not be disclosed and it should not be given or copied to anyone
other than the person(s) named or referenced above. If you are not the
intended recipient or the person responsible for delivering to the
intended recipient, be advised that you have received this email in
error and that any use is strictly prohibited. 

If you have received this email in error please notify sender
immediately on +44 (0161) 276 5782

 



Re: [PHP] php code to upload a url correctly

2007-01-26 Thread Németh Zoltán
On p, 2007-01-26 at 14:10 +, Corden James (RW3) CMMC Manchester
wrote:
 I have a form in which users submit a url. I am having problems as some
 people submit the url in the format http://www.blah.blah.org
 http://www.blah.blah.org/  while others submit in the format
 www.blah.blah.org http://www.blah.blah.org/  I have designed the form
 so that it seems fairly obvious (to me anyway) not to include the
 http:// but people are still doing it (presumably because they are
 copying and pasting from a browser). My form processing script is
 designed to add http:// to the submitted url and place the modified url
 in a database for future use. As you can imagine sometimes I end up with
 urls such as http://http://www.blah.blah.org
 http://http:/www.blah.blah.org  in my database. Hence I need a more
 rigorous form processing script that is capable of first checking if the
 url includes http:// and then processes accordingly. Can anyone point me
 in the right direction for such a script?
 
  
 

You should first check the url and only add http://; at the beginning
if its not there

I do it like

if (substr($url, 0, 4) != http) {$url = http://; . $url;}

in my website, although it is probably not the most elegant solution ;)

hope that helps
Zoltán Németh

 Thanks
 
  
 
 Dr James Corden
 
 Technology Evaluation Manager
 
 TrusTECH, Innovation Unit
 
 1st Floor Postgraduate Centre
 
 Manchester Royal Infirmary
 
 Oxford Road
 
 Manchester 
 
 M13 9WL
 
  
 
 Tel:   0161 276 5782
 
 Fax:  0161 276 5766
 
 E-mail: [EMAIL PROTECTED]
 
 Web: http://www.trustech.org.uk
 
 This email and any files transmitted with it are confidential and solely
 for the use of the intended recipient. It may contain material protected
 by law as a legally privileged document and copyright work. Its content
 should not be disclosed and it should not be given or copied to anyone
 other than the person(s) named or referenced above. If you are not the
 intended recipient or the person responsible for delivering to the
 intended recipient, be advised that you have received this email in
 error and that any use is strictly prohibited. 
 
 If you have received this email in error please notify sender
 immediately on +44 (0161) 276 5782
 
  
 

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



Re: [PHP] php code to upload a url correctly

2007-01-26 Thread Dave Goodchild

This is what I use:

$site = (!preg_match('#^http://#', $_POST['c_site'])) ?
raw_param(trim(strip_tags(http:\/\/ . $_POST['c_site']))) :
raw_param(trim(strip_tags($_POST['c_site'])));

don't worry about raw_param, that's a function of my own, but you get the
idea.


Re: [PHP] php code to upload a url correctly

2007-01-26 Thread Jochem Maas
Németh Zoltán wrote:
 On p, 2007-01-26 at 14:10 +, Corden James (RW3) CMMC Manchester
 wrote:
 I have a form in which users submit a url. I am having problems as some
 people submit the url in the format http://www.blah.blah.org
 http://www.blah.blah.org/  while others submit in the format
 www.blah.blah.org http://www.blah.blah.org/  I have designed the form
 so that it seems fairly obvious (to me anyway) not to include the
 http:// but people are still doing it (presumably because they are
 copying and pasting from a browser). My form processing script is
 designed to add http:// to the submitted url and place the modified url
 in a database for future use. As you can imagine sometimes I end up with
 urls such as http://http://www.blah.blah.org
 http://http:/www.blah.blah.org  in my database. Hence I need a more
 rigorous form processing script that is capable of first checking if the
 url includes http:// and then processes accordingly. Can anyone point me
 in the right direction for such a script?

  

 
 You should first check the url and only add http://; at the beginning
 if its not there
 
 I do it like
 
 if (substr($url, 0, 4) != http) {$url = http://; . $url;}
 
 in my website, although it is probably not the most elegant solution ;)

it will break in the highly unlikely situation that someone uploads a url like:

http.mydomain.com

an also for things like:

ftp://leet.haxordownload.org/

2 alternatives spring to mind:

1. a beasty little regex.
2. use the output of parse_url().

the second is by far the better way of doing this, below a couple of
examples:

?php

var_dump(
parse_url(http.mydomain.com/foo.php?id=1),
parse_url(https://www.foo.org/html.html?arg=a;),
parse_url(ftp://leet.haxordl.org;)
);

?

hopefully the OP has enough brains (I'll assume he does given the 'Dr' title he 
carries :-)
to figure out how to use the output to be able to always generate a valid url 
from whatever
people are sticking in his form (and/or return a suitable error if someone 
tries to insert
some complete rubbish)

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



Re: [PHP] Re: two php.ini on the same server

2007-01-26 Thread phpdevster

 Setting two virtual hosts, one for php4 and other for php5

that might be useful but what i really need is to run any version of php on
the first httpd . the second httpd should be php5 . the two php and httpd
have separate configuration .

the exactly what i need is to load php extension on the second httpd that i
don't want it to be available for the first httpd . i think if it is
possible to install php4 and php5 on the same server it will be easy to
install two copies of php5 or use two php.ini files .

i am using fedora core 5 with apache 2 and php5


Re: [PHP] php code to upload a url correctly

2007-01-26 Thread Jochem Maas
Dave Goodchild wrote:
 This is what I use:
 
 $site = (!preg_match('#^http://#', $_POST['c_site'])) ?
 raw_param(trim(strip_tags(http:\/\/ . $_POST['c_site']))) :
 raw_param(trim(strip_tags($_POST['c_site'])));

this is much better: http://php.net/parse_url

 
 don't worry about raw_param, that's a function of my own, but you get the
 idea.

wouldn't it have been less hassle to delete the raw_param() call than
to try and explain it's existence?

 

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



Re: [PHP] php code to upload a url correctly

2007-01-26 Thread Németh Zoltán
On p, 2007-01-26 at 16:46 +0100, Jochem Maas wrote:
 Németh Zoltán wrote:
  On p, 2007-01-26 at 14:10 +, Corden James (RW3) CMMC Manchester
  wrote:
  I have a form in which users submit a url. I am having problems as some
  people submit the url in the format http://www.blah.blah.org
  http://www.blah.blah.org/  while others submit in the format
  www.blah.blah.org http://www.blah.blah.org/  I have designed the form
  so that it seems fairly obvious (to me anyway) not to include the
  http:// but people are still doing it (presumably because they are
  copying and pasting from a browser). My form processing script is
  designed to add http:// to the submitted url and place the modified url
  in a database for future use. As you can imagine sometimes I end up with
  urls such as http://http://www.blah.blah.org
  http://http:/www.blah.blah.org  in my database. Hence I need a more
  rigorous form processing script that is capable of first checking if the
  url includes http:// and then processes accordingly. Can anyone point me
  in the right direction for such a script?
 
   
 
  
  You should first check the url and only add http://; at the beginning
  if its not there
  
  I do it like
  
  if (substr($url, 0, 4) != http) {$url = http://; . $url;}
  
  in my website, although it is probably not the most elegant solution ;)
 
 it will break in the highly unlikely situation that someone uploads a url 
 like:
 
   http.mydomain.com
 
 an also for things like:
 
   ftp://leet.haxordownload.org/
 
 2 alternatives spring to mind:
 
   1. a beasty little regex.
   2. use the output of parse_url().

parse_url is a great idea, I think I will use that in the future

thanks Jochem

greets
Zoltán Németh

 
 the second is by far the better way of doing this, below a couple of
 examples:
 
 ?php
 
 var_dump(
   parse_url(http.mydomain.com/foo.php?id=1),
   parse_url(https://www.foo.org/html.html?arg=a;),
   parse_url(ftp://leet.haxordl.org;)
 );
 
 ?
 
 hopefully the OP has enough brains (I'll assume he does given the 'Dr' title 
 he carries :-)
 to figure out how to use the output to be able to always generate a valid url 
 from whatever
 people are sticking in his form (and/or return a suitable error if someone 
 tries to insert
 some complete rubbish)

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



Re: [PHP] Re: two php.ini on the same server

2007-01-26 Thread Myron Turner

zerof wrote:

phpdevster escreveu:

Hi

i am trying to run two Apache server on the same machine and that is 
work

fine

but the problem is how to create separate php.ini for each Apache 
server .

is that possible ??


Two usual possibilities:

1) To install two Apache Services ( Windows environment )

   Apache 1.3.xx running php 4
   Apache 2 running php 5

   http://www.educar.pro.br/

2) To use only one Apache2 Service

   Setting two virtual hosts, one for php4 and other for php5

   http://foundationphp.com/tutorials/apache22_vhosts.php
I've done this (1) on linux and it works fine, php 4 on 1.3xx and 5 php 
5 on apache 2.   I believe the reason this works is that you have two 
php executables, each with unique configurations.  So, if you, say, 
wanted to have php 5 running two apache servers, it would probably work 
if you recompile php 5 and install it into a new directory.  I have no 
experience with windows.  But here are some notes for installing on 
linux/unix machines:


If your system already came with a pre-installed php 5 executable, then 
when you download and compile the new php 5, it will automatically 
install in /usr/local.  But if you had previously compiled php 5 and it 
is already in /usr/local, you might want to install in a new directory, 
which you can do by feeding configure a new prefix:

  ./configure --prefix=/usr/local/new_install_directory
You might also want to feed configure a path for the php.ini file:
  ./configure --prefix=/usr/local/new_install_directory 
--with-config-file-path=PATH

But if you don't, php.ini will automatically be installed in PREFIX/lib:
  /usr/local/new_install_directory/lib

You will have to read the INSTALL file that comes with the 
distribtution, becaue you also have to set a few other basic values for 
configure to work with.



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread tg-php
My contribution to the insanity..  INSERT statements made easy:

$genericQY  = INSERT INTO MOD_LMGR_Leads (;  $genericQYvalues  =  VALUES (;
$genericQY .=  FirstName,;   $genericQYvalues .=  'John',;
$genericQY .=  LastName; $genericQYvalues .=  'Smith';
$genericQY .=  );$genericQYvalues .=  );;
$genericQY .= $genericQYvalues;
$genericRS = mysql_query($genericQY);


I use this structure so if I decide that I don't need certain data I can 
comment out a single line to remove the column name and corresponding value.  
Also helpful for making updates to column/value pairs and not worry about the 
dreaded error involve # of columns not matching.

Only things you have to watch for:

1. Make sure you don't have a comma on the last item
2. Make sure you have spaces where appropriate so when it concatenates the 
strings, you don't get stuff crammed together (not really an issue with the 
INSERT statement, but I try to keep a consistant practice with all my queries 
so I don't slip up..   SELECT columnsFROM tableWHERE something = something is 
where it really gets ya if you forget spaces.. just as an example)
3. Make sure to remember to concatenate the query and values parts

I like to think this is a little outside the box thinking since common 
practice is one command, one line or total chaos hah.

Any comments on improving this or other unique stylistic ways people like to 
design their code?

-TG


= = = Original message = = =

On Wed, January 24, 2007 8:07 pm, Robert Cummings wrote:
 On Wed, 2007-01-24 at 18:23 -0600, Richard Lynch wrote:
 On Wed, January 24, 2007 7:41 am, Roman Neuhauser wrote:
  # [EMAIL PROTECTED] / 2007-01-24 13:57:03 +0200:
  and also in these days I'm looking for 19 inch (or more) wide LCD
  sceerns to able to fit longer lines in my screen...
 
  Number of reading errors people make grows with line length,
  this has been known for as long as I remember.  You're increasing
 the
  probability of bugs in the code, and get tired sooner because
  following
  long lines requires more energy.

 I believe those results are specific to what is being read.

 Surely it's easier to read:

 SELECT blah, blah, blah, blah, blah, blah, blah, blah, blah

 if it's all on one line, no matter how many fields there are, while
 trying to read the code as a whole.

 Sure, it can be hard to find/read the individual field names, on
 the
 rare occasion that you need to do that...

 Dear Mr Lynch, normally I highly respect your commentary on the list,
 but today I think you've been-a-smoking the crackpipe a tad too much.

 There is no way in hell one long line of SQL is easier to read than
 formatted SQL that clearly delineates the clause structure.

 SELECT A.field1 AS afield1, A.field2 AS afield2, B.field1 AS bfield1,
 B.field2 AS bfield2, C.field1 AS cfield1, C.field2 AS cfield2,
 D.field1
 AS dfield1, D.field2 AS dfield2 FROM tableA as A LEFT JOIN tableB AS B
 ON B.fee = A.foo LEFT JOIN tableC AS C ON C.fii = B.fee LEFT JOIN
 tableD
 AS D ON D.fuu = C.fii WHERE A.foo = 'someValue' ORDER BY afield1 ASC,
 cfield2 ASC

 The above line should be on one line, but my email client might
 autowrap it. Either way, the following is formatted and is much
 clearer.

 SELECT
 A.field1 AS afield1,
 A.field2 AS afield2,
 B.field1 AS bfield1,
 B.field2 AS bfield2,
 C.field1 AS cfield1,
 C.field2 AS cfield2,
 D.field1 AS dfield1,
 D.field2 AS dfield2
 FROM
 tableA as A
 LEFT JOIN tableB AS B ON
 B.fee = A.foo
 LEFT JOIN tableC AS C ON
 C.fii = B.fee
 LEFT JOIN tableD AS D ON
 D.fuu = C.fii
 WHERE
 A.foo = 'someValue'
 ORDER BY
 afield1 ASC,
 cfield2 ASC


 While the above is contrived, most of us know such examples happen
 quite
 often in the wild. Not only is it easier to read, but the task of
 adding
 or removing selected fields is trivial.

I meant ONLY the SELECT part on a single line.

Only a moron would cram the FROM and all that into the same line.
:-)

$query = SELECT blah1, blah2, blah3, ... blah147 ;
$query .=  FROM table1 ;
$query .=  LEFT OUTER JOIN table2 ;
$query .= ON blah7 = blah42 ;
$query .=  WHERE blah16 ;
$query .=AND blah42 ;
$query .=  ORDER BY blah9, blah8 desc, blah6 ;

is what I go for.

The SELECT line is the only one that ever gets all that long, really...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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



Re: [PHP] php code to upload a url correctly

2007-01-26 Thread Stut

Jochem Maas wrote:

Németh Zoltán wrote:

You should first check the url and only add http://; at the beginning
if its not there

I do it like

if (substr($url, 0, 4) != http) {$url = http://; . $url;}

in my website, although it is probably not the most elegant solution ;)


it will break in the highly unlikely situation that someone uploads a url like:

http.mydomain.com

an also for things like:

ftp://leet.haxordownload.org/

2 alternatives spring to mind:

1. a beasty little regex.
2. use the output of parse_url().

the second is by far the better way of doing this


Using parse_url for this seems like overkill to me. Just check the 
string for the presence of :// and prepend http:// if it's missing.


if (false === strpos($url, '://'))
{
$url = 'http://'.$url;
}

There will be fringe cases where someone might enter 
example.com/jumpto?url=http://othersite.org/, in which case do the check 
up to the first '.'.


if (false === strpos(substr($url, 0, strpos($url, '.'), '://'))
{
$url = 'http://'.$url;
}

I don't have numbers, but I'd bet this is quicker than doing a parse_url.

-Stut

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
 My contribution to the insanity..  INSERT statements made easy:
 

can't stand long var names if they're not absolutely necessary (JMO).
although I follow TG's logic here I don't find it that readable, too many
dots, [double]quotes, etc for my taste.

 $genericQY  = INSERT INTO MOD_LMGR_Leads (;  $genericQYvalues  =  VALUES 
 (;
 $genericQY .=  FirstName,;   $genericQYvalues .=  'John',;
 $genericQY .=  LastName; $genericQYvalues .=  'Smith';
 $genericQY .=  );$genericQYvalues .=  );;
 $genericQY .= $genericQYvalues;
 $genericRS = mysql_query($genericQY);


// init
$data = array();

// get (or make up) data
$data['FirstName']= 'John';
$data['LastName'] = 'Smith';
//$data['Prefers']  = 'bitter';
//$data['promotedby']   = 'Jack Dee';

// build it
if (!empty($data)) {
$flds = join(',', array_keys($data));
$vals = join(',', $data);
$qry  = INSERT INTO MOD_LMGR_Leads ($flds) VALUES ($vals);
} else {
die(ya think I'm stupid enough to insert nothing?);
}

// run it
$res  = mysql_query($qry);

that was kind of step one of building a generic qry builder, of which there
are many :-) (and many ways to go about it)

when writing specific/custom queries I find the example below to
be the most readable way:


...


 SELECT
 A.field1 AS afield1,
 A.field2 AS afield2,
 B.field1 AS bfield1,
 B.field2 AS bfield2,
 C.field1 AS cfield1,
 C.field2 AS cfield2,
 D.field1 AS dfield1,
 D.field2 AS dfield2
 FROM
 tableA as A
 LEFT JOIN tableB AS B ON
 B.fee = A.foo
 LEFT JOIN tableC AS C ON
 C.fii = B.fee
 LEFT JOIN tableD AS D ON
 D.fuu = C.fii
 WHERE
 A.foo = 'someValue'
 ORDER BY
 afield1 ASC,
 cfield2 ASC



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



Re: [PHP] php code to upload a url correctly

2007-01-26 Thread Jochem Maas
Stut wrote:
 Jochem Maas wrote:
 Németh Zoltán wrote:


...

 
 I don't have numbers, but I'd bet this is quicker than doing a parse_url.

I didn't realise speed was an issue. and if it really was an issue I would 
suggest
offloading the url normailization into a batch routine that is run outside of 
any
web request - i.e. merely take the input store it somewhere as-is for later
normalization and insertion into the DB. (most likely total overkill)

personally I think robustness  correctness are more important than speed.

 
 -Stut
 

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread Stut

[EMAIL PROTECTED] wrote:

My contribution to the insanity..  INSERT statements made easy:

$genericQY  = INSERT INTO MOD_LMGR_Leads (;  $genericQYvalues  =  VALUES (;
$genericQY .=  FirstName,;   $genericQYvalues .=  'John',;
$genericQY .=  LastName; $genericQYvalues .=  'Smith';
$genericQY .=  );$genericQYvalues .=  );;
$genericQY .= $genericQYvalues;
$genericRS = mysql_query($genericQY);


You call that readable??

$vals = array();
$vals['FirstName'] = 'John';
$vals['LastName'] = 'Smith';
$query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals));

function BuildInsert($table, $values)
{
foreach (array_keys($values) as $key)
$values[$key] = mysql_real_escape_string($values[$key]);

$sql = 'insert into `'.$table.'` (`';
$sql.= implode('`,`', array_keys($values));
$sql.= '`) values (';
$sql.= implode(',', array_values($values));
$sql.= ')';

return $sql;
}

Note that this is a *very* cut down and untested version of BuildInsert.

-Stut

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



Re: [PHP] php code to upload a url correctly

2007-01-26 Thread Jochem Maas
Dave Goodchild wrote:
 Wouldn't it have been less hassle to not send that comment when all I
 was doing was trying to help, am pressed for time, and copied and pasted
 my solution?

no hassle on my part. :-D

I doubt you want me to point out that you original
comment that I commented on and the reply thereof
you sent both constitute a greater waste of your time
(and less confusion on the part of the OP) than if you had
just removed the 'raw_param' from your original code snippet),
given that your so 'pressed for time' (which is, in essence, nothing more
than a state of mind).

do or do not, there is no try said the funnny, little green man.

 
 On 1/26/07, * Jochem Maas* [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote:
 
 Dave Goodchild wrote:
  This is what I use:
 
  $site = (!preg_match('#^http://#', $_POST['c_site'])) ?
  raw_param(trim(strip_tags(http:\/\/ . $_POST['c_site']))) :
  raw_param(trim(strip_tags($_POST['c_site'])));
 
 this is much better: http://php.net/parse_url
 
 
  don't worry about raw_param, that's a function of my own, but you
 get the
  idea.
 
 wouldn't it have been less hassle to delete the raw_param() call than
 to try and explain it's existence?
 
 
 
 
 
 
 -- 
 http://www.web-buddha.co.uk

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



Re: [PHP] php javascript interaction

2007-01-26 Thread Myron Turner

William Stokes wrote:

Hello,

I need some advice on how to learn Javascript and PHP interaction. Any good 
tutorials on the web would be most welcome. I particulary need to learn how 
to pass JS user input/choices to PHP.


My current problem is how to ask user confirmation over his actions on a web 
form after POST. Are you sure type questions and how to pass the user 
choice back to program make choices with PHP.


Thanks
-Will

  
For the second question try google with something like javascript form 
submit.


For the first question, see:
http://ca.php.net/manual/en/language.variables.predefined.php
Form data is captured in PHP in a number of different predefined 
variables accessible from your scripts.  This page defines these varibables.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread Jon Anderson
This may not be an option for many people, 'cause ISPs and web hosts may 
not be forward-thinking enough to install PDO or recent PHP, but...


PDO can do do this in a very database independant way, without having to 
do the equivalent of mysql_real_escape_string:


$table = 'xyz';
$data = array(
   'Field1' = Data1,
   'Field2' = Data2
);

$fields = implode(',',array_keys($data));
$placeholders = ':' . implode(',:',array_keys($data));
$stmt = $dbh-prepare(INSERT INTO $table ($fields) VALUES($placeholders));
$stmt-execute($data);

With the added bonus that you can insert multiple rows quickly without 
having to rebuild any queries...


$stmt-execute($data1);
$stmt-execute($data2);
...
$stmt-execute($dataN);

(And PDO is super-fast compared to some other similar PHP-based libraries.)

jon

[EMAIL PROTECTED] wrote:

My contribution to the insanity..  INSERT statements made easy:

$genericQY  = INSERT INTO MOD_LMGR_Leads (;  $genericQYvalues  =  
VALUES (;
$genericQY .=  FirstName,;   $genericQYvalues .=  
'John',;
$genericQY .=  LastName; $genericQYvalues .=  
'Smith';
$genericQY .=  );$genericQYvalues .=  
);;

$genericQY .= $genericQYvalues;
$genericRS = mysql_query($genericQY);


You call that readable??

$vals = array();
$vals['FirstName'] = 'John';
$vals['LastName'] = 'Smith';
$query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals));

function BuildInsert($table, $values)
{
foreach (array_keys($values) as $key)
$values[$key] = mysql_real_escape_string($values[$key]);

$sql = 'insert into `'.$table.'` (`';
$sql.= implode('`,`', array_keys($values));
$sql.= '`) values (';
$sql.= implode(',', array_values($values));
$sql.= ')';

return $sql;
}

Note that this is a *very* cut down and untested version of BuildInsert.

-Stut



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



[PHP] stream_socket_pair

2007-01-26 Thread Bob Dusek
Are sockets created via stream_socket_pair more efficient for IPC than
standard socket/port communications?

I want to open a process with proc_open, and I want to use a socket to
for IPC.  One solution is to just create a socket in the parent and pass
the port number to the child.  Then, when the child starts, it would
connect to the local port via a socket.  

Would it be better to use stream_socket_pair to create a pair of IPC
socets and then somehow pass the socket descriptor via the proc_open
call? 

Does anyone have any experience passing a socket handle via the
descriptor array in proc_open? 

Thanks,

Bob

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread Jochem Maas
Jon Anderson wrote:
 This may not be an option for many people, 'cause ISPs and web hosts may
 not be forward-thinking enough to install PDO or recent PHP, but...
 
 PDO can do do this in a very database independant way, without having to
 do the equivalent of mysql_real_escape_string:
 
 $table = 'xyz';
 $data = array(
'Field1' = Data1,
'Field2' = Data2
 );
 
 $fields = implode(',',array_keys($data));
 $placeholders = ':' . implode(',:',array_keys($data));
 $stmt = $dbh-prepare(INSERT INTO $table ($fields)
 VALUES($placeholders));
 $stmt-execute($data);
 
 With the added bonus that you can insert multiple rows quickly without
 having to rebuild any queries...
 
 $stmt-execute($data1);
 $stmt-execute($data2);
 ...
 $stmt-execute($dataN);
 
 (And PDO is super-fast compared to some other similar PHP-based libraries.)

unless your using firebird (http://php.net/ibase), in which case PDO is useless.
not that that matters because the ibase extension does this (and has done this 
for
longer than PDO has existed) natively (as in the DB engine does the real 
parameter
related lifting, as opposed to some php extension - no offence to php devs but 
I'd
rather entrust this to the people who developed the data base engine) and 
additionally
the ibase extension is much more intuitive when it comes parameterized queries.

$res = ibase_query('INSERT INTO foo (first, last) VALUES (?, ?)', $first, 
$last);



[no that wasn't very helpful was it :-P]

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread tg-php
Strangely enough, Stut and Jochem, I DO find this more readable. Hah. I know, 
I'm insane.  I have done it the way you guys proposed, using an associative 
array and using the keys and values as the columns and insert values.  While 
that is what I'd call tighter code and when you understand what it's doing, 
is just as simple to maintain as how I do it, I do find my method more 
'readable'.

I tend to build queries in WinSQL first, then insert them into my PHP code.  
Some of which are fairly complicated and I find if I keep my PHP code similar 
to my SQL code, it makes it easier to go back and forth to tweak it.  They both 
have a similar look to me.

So instead of using:

$query  = SELECT BunchOfJoinedColumns;
$query .=  FROM BunchOfJoinedTables;
$query .=  WHERE SomeConditions;
$query .=  AND MoreConditions;

for long complicated SELECT statements, then using the method you guys use for 
INSERT statements, I'm keeping my code consistant whether it's SELECT, INSERT, 
UPDATE, whatever.

To me, consistancy wins out in a choice between two (imo) equally easily 
maintained coding styles.

But hey.. I'm always willing to learn new stuff.  One reason I posted this was 
to see more of what other people did with their code, SQL queries in particular.

Cheers!

-TG



= = = Original message = = =

[EMAIL PROTECTED] wrote:
 My contribution to the insanity..  INSERT statements made easy:
 
 $genericQY  = INSERT INTO MOD_LMGR_Leads (;  $genericQYvalues  =  VALUES 
 (;
 $genericQY .=  FirstName,;   $genericQYvalues .=  'John',;
 $genericQY .=  LastName; $genericQYvalues .=  'Smith';
 $genericQY .=  );$genericQYvalues .=  );;
 $genericQY .= $genericQYvalues;
 $genericRS = mysql_query($genericQY);

You call that readable??

$vals = array();
$vals['FirstName'] = 'John';
$vals['LastName'] = 'Smith';
$query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals));

function BuildInsert($table, $values)

 foreach (array_keys($values) as $key)
 $values[$key] = mysql_real_escape_string($values[$key]);

 $sql = 'insert into `'.$table.'` (`';
 $sql.= implode('`,`', array_keys($values));
 $sql.= '`) values (';
 $sql.= implode(',', array_values($values));
 $sql.= ')';

 return $sql;


Note that this is a *very* cut down and untested version of BuildInsert.

-Stut


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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



[PHP] memory_limit Setting?

2007-01-26 Thread Jay Paulson
Hi everyone,

I¹m trying to upload a 25MB file via PHP and I¹m setting the memory limit
way high so I don¹t get a fatal error from php (the error is below).  What I
find really odd about this is that the error message says that PHP tried to
allocate almost 54MB.  First question is why is PHP allocating so much
memory when I¹m only uploading a 25MB file?  Second question is why is PHP
failing when obviously the memory limit is set to just over 100MB?  (I¹m
using PHP 5.1.2 Apache 2.0.55 and using an .htaccess file to change the PHP
settings on the fly.)


Fatal error: Allowed memory size of 104857600 bytes exhausted (tried to
allocate 53764163 bytes) in /path/to/php/file on line 942

.htaccess settings below:

php_value memory_limit 100M
php_value post_max_size 30M
php_value upload_max_filesize 30M
php_value max_execution_time 300
php_value max_input_time 300
php_value display_errors On


Re: [PHP] memory_limit Setting?

2007-01-26 Thread Jon Anderson

Jay Paulson wrote:

Hi everyone,

I¹m trying to upload a 25MB file via PHP and I¹m setting the memory limit
way high so I don¹t get a fatal error from php (the error is below).  What I
find really odd about this is that the error message says that PHP tried to
allocate almost 54MB.  First question is why is PHP allocating so much
memory when I¹m only uploading a 25MB file?
Question is what does your code look like? AFAIK, PHP uploads files to a 
temp directory where you can do whatever you want with them. If you 
don't read them into memory, it won't use a lot of memory (just the 
overhead required for the $_FILES array).

Second question is why is PHP
failing when obviously the memory limit is set to just over 100MB?
It's trying to allocate over 50M, but fails because existing memory 
usage + attempted memory usage  is greater than 100M. Call 
memory_get_usage() right before the line on which it fails to see how 
much memory is being used by your script.


jon

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread Satyam
- Original Message - 
From: Stut [EMAIL PROTECTED]

You call that readable??

$vals = array();
$vals['FirstName'] = 'John';
$vals['LastName'] = 'Smith';
$query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals));

function BuildInsert($table, $values)
{
foreach (array_keys($values) as $key)
$values[$key] = mysql_real_escape_string($values[$key]);

$sql = 'insert into `'.$table.'` (`';
$sql.= implode('`,`', array_keys($values));
$sql.= '`) values (';
$sql.= implode(',', array_values($values));
$sql.= ')';

return $sql;
}



I use to build SQL statements with a BuildSql function, which you can see 
at:  http://www.satyam.com.ar/int/BuildSql.php


It is commented in PhpDoc format.

For example:

echo BuildSql('Insert into ?ptable 
(?s,?ns,?mi,?d,?ni,?i,?t)','Something','',5,time(),0,null,mktime(3,4,5)- 
mktime(0,0,0));



Will return:

Insert into wp_table ('Something',null,5,'2007-01-21 15:54:27',null,0,'0 
04:04:05')


It is not only meant to build inserts but it is more like a sort of 
SQL-oriented sprintf(), like it does proper handling of null values, such as 
avoiding puting the text 'null' (notice the quotes) instead of the value 
null.  It also has a ?p 'prefix' modifier to use a fixed prefix on all table 
names.


As for formatting, I usually put the SQL statement in one line and the 
arguments in the next one with spaces to align them vertically, which I 
won't show here since the formatting of the message will ruin it anyway.


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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread Robert Cummings
On Fri, 2007-01-26 at 16:30 +, Stut wrote:
 [EMAIL PROTECTED] wrote:
  My contribution to the insanity..  INSERT statements made easy:
  
  $genericQY  = INSERT INTO MOD_LMGR_Leads (;  $genericQYvalues  =  VALUES 
  (;
  $genericQY .=  FirstName,;   $genericQYvalues .=  
  'John',;
  $genericQY .=  LastName; $genericQYvalues .=  
  'Smith';
  $genericQY .=  );$genericQYvalues .=  );;
  $genericQY .= $genericQYvalues;
  $genericRS = mysql_query($genericQY);
 
 You call that readable??
 
 $vals = array();
 $vals['FirstName'] = 'John';
 $vals['LastName'] = 'Smith';
 $query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals));

Geee, you call that readable???

$vals = array
(
'FirstName' = 'John',
'LastName'  = 'Smith',
);

$query = mysql_query( BuildInsert( 'MOD_LMGR_Leads', $vals ) );

;) ;)

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread Robert Cummings
On Fri, 2007-01-26 at 12:25 -0500, [EMAIL PROTECTED] wrote:
 Strangely enough, Stut and Jochem, I DO find this more readable. Hah. I know, 
 I'm insane.  I have done it the way you guys proposed, using an associative 
 array and using the keys and values as the columns and insert values.  While 
 that is what I'd call tighter code and when you understand what it's doing, 
 is just as simple to maintain as how I do it, I do find my method more 
 'readable'.
 
 I tend to build queries in WinSQL first, then insert them into my PHP code.  
 Some of which are fairly complicated and I find if I keep my PHP code similar 
 to my SQL code, it makes it easier to go back and forth to tweak it.  They 
 both have a similar look to me.
 
 So instead of using:
 
 $query  = SELECT BunchOfJoinedColumns;
 $query .=  FROM BunchOfJoinedTables;
 $query .=  WHERE SomeConditions;
 $query .=  AND MoreConditions;

 But hey.. I'm always willing to learn new stuff.
 One reason I posted this was to see more of what other
 people did with their code, SQL queries in particular.

My insert style is very similar to my select style:

?php

$query =
INSERT INTO someTable 
   .( 
   .field1, 
   .field1, 
   .field1 
   .) 
   .VALUES 
   .( 
   ..$db-quote( $value1 )., 
   ..$db-quote( $value2 )., 
   ..$db-quote( $value3 ). 
   .) ;

?

Or if there's a lot of fields:

?php

$data = array
(
'field1' = $value1,
'field2' = $value2,
'field3' = $value3,
...
);

$query =
INSERT INTO someTable 
   .( 
   .implode( , , array_keys( $data ) ). 
   .) 
   .VALUES 
   .( 
   .implode( , , $db-quoteArray( $data ) ). 
   .) ;

?

Although, I don't find myself doing much in the way of inserts these
days since I often extend a data object class that performs the inserts
and updates as necessary.

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



Re: [PHP] Ongoing encoding issues

2007-01-26 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-01-26 09:33:13 +:
 Hi all, I posted a question a couple of days ago regarding a web app I have
 wherein users are able to indicated prices and concessions via a text field,
 and the resulting encoding issues I have experienced, the main one being
 seeing the pound sign as Â? if viewing the results in a browser with the
 encoding set to Latin-1.
 
 My question is, how do I overcome this. If I set my browser encoding to
 Latin-1 and enter the data I get that odd symbol, if I set it to UTF-8 I get
 clean data. Is there a way to sniff out what encoding the browser is using
 and then clean the data in any way.
 
 I am googling for help also but you guys have been so helpful in the past I
 thought I'd try you also.

Your PostgreSQL database uses some encoding, your PHP script runs under
some locale (incl. character encoding), and the browser sent the text in
some encoding.  PostgreSQL assumes the input data is in the charset the
database uses (unless you have client_encoding set in postgresql.conf, or
PGCLIENTENCODING (IIRC) in the environment, or have set client_encoding
using the SET command).

It's important that you correctly identify encoding of the inserted data
to PostgreSQL or convert it to the encoding it expects beforehand.  You
can use iconv or recode functions in PHP, I'd probably have a look if
there's an apache input filter for character encoding conversions.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] memory_limit Setting?

2007-01-26 Thread Sancar Saran
On Friday 26 January 2007 19:35, Jay Paulson wrote:
 Hi everyone,

 I¹m trying to upload a 25MB file via PHP and I¹m setting the memory limit
 way high so I don¹t get a fatal error from php (the error is below).  What
 I find really odd about this is that the error message says that PHP tried
 to allocate almost 54MB.  First question is why is PHP allocating so much
 memory when I¹m only uploading a 25MB file?  Second question is why is PHP
 failing when obviously the memory limit is set to just over 100MB?  (I¹m
 using PHP 5.1.2 Apache 2.0.55 and using an .htaccess file to change the PHP
 settings on the fly.)


 Fatal error: Allowed memory size of 104857600 bytes exhausted (tried to
 allocate 53764163 bytes) in /path/to/php/file on line 942

 .htaccess settings below:

 php_value memory_limit 100M
 php_value post_max_size 30M
 php_value upload_max_filesize 30M
 php_value max_execution_time 300
 php_value max_input_time 300
 php_value display_errors On

In these days combining UTF-8 with serialize commands gives memory problems. 
Is your code coantains this combination.

?

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



Re: [PHP] Multi lingual pages

2007-01-26 Thread Otto Wyss

Paul Novitski wrote:

I formulated my question in general since I couldn't find an other 
message here about supporting multiple languages.



http://www.w3.org/International/articles/

http://www.w3.org/TR/i18n-html-tech-lang/

http://php.net/setlocale


Thanks a lot, these are good points for reading.


1) Switching language downloads a new version of the current page, 
generally with the same markup but new text.  Example:

http://partcon.ca/


I'll favor this way especially if several languages have to be provided.

In both cases I store the text in database tables that contain a 
language field I can select on to match the user's request.


I wonder if retrieving static texts from the database draws too much 
performance. I know from somebody who stores texts in large data arrays 
an uses shared memory, yet I haven't figured it out how.


I consider storing static texts as defines and just load a different 
definition file when the user switches language. Is this practical?


O. Wyss

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



Re: [PHP] Multi lingual pages

2007-01-26 Thread Robert Cummings
On Fri, 2007-01-26 at 21:25 +0100, Otto Wyss wrote:
 Paul Novitski wrote:
 
 I formulated my question in general since I couldn't find an other 
 message here about supporting multiple languages.
 
  http://www.w3.org/International/articles/
  
  http://www.w3.org/TR/i18n-html-tech-lang/
  
  http://php.net/setlocale
  
 Thanks a lot, these are good points for reading.
  
  1) Switching language downloads a new version of the current page, 
  generally with the same markup but new text.  Example:
  http://partcon.ca/
  
 I'll favor this way especially if several languages have to be provided.
 
  In both cases I store the text in database tables that contain a 
  language field I can select on to match the user's request.
  
 I wonder if retrieving static texts from the database draws too much 
 performance. I know from somebody who stores texts in large data arrays 
 an uses shared memory, yet I haven't figured it out how.

Sure it does, but you can accumulate all the retrieved texts for a page
and cache them so subsequent hits only require a query for the cached
entries. If the page has some translations that may or may not show up
depending on certain values, then you can retrieve the cache, update the
cache with each translation not previously cached and then re-store the
cache. After a while you'll only make 1 query (2 if you're sloppy and
don't check a dirty bit for if the cache actually changed :)

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] PHP with XML database

2007-01-26 Thread Ritesh Nadhani

Hello all

As part of my research under my professor I have to implement a web 
interface to their benchmarking data.


PHP is the chosen web language but we are little worried about the 
database. The benchmark data comes to us in XML format (e.g. 
http://www.matf.bg.ac.yu/~filip/ArgoLib/smt-lib-xml/Examples/FolEq1.xml).

We have to implement an interface to query them, get data, update etc.

We even can change schema in the form of attributes. . The data size 
would be around 100 MB each XML with around 100 different XMLs.


The load would be max 5-10 users any given time, batch updates once a 
month and heavy load probably 2-3 times a month. Mission criticality is 
not important, we can get it down sometimes. Which db would you suggest?


I did Google research and as of now - I like eXist, Sedna (they seem to 
have good PHP wrapper support) and Timber. Another thing would be good 
documentation and support.


Any suggestions?

Ritesh

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



Re: [PHP] php javascript interaction

2007-01-26 Thread Scripter47

Myron Turner skrev:

William Stokes wrote:

Hello,

I need some advice on how to learn Javascript and PHP interaction. Any 
good tutorials on the web would be most welcome. I particulary need to 
learn how to pass JS user input/choices to PHP.


My current problem is how to ask user confirmation over his actions on 
a web form after POST. Are you sure type questions and how to pass 
the user choice back to program make choices with PHP.


Thanks
-Will

  
For the second question try google with something like javascript form 
submit.


For the first question, see:
http://ca.php.net/manual/en/language.variables.predefined.php
Form data is captured in PHP in a number of different predefined 
variables accessible from your scripts.  This page defines these 
varibables.



Use AJAX

Link: http://javascript.internet.com/ajax/ajax-navigation.html

is migth be what you are looking for:
http://javascript.internet.com/ajax/check-username-signup.html


The cool thing with AJAX is that it can load pages while viewing the 
webpage. Without updating it!


check out this chat i made with it:
http://wsd.riddergarn.dk/index.php?p=chat

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



Re: [PHP] Multi lingual pages

2007-01-26 Thread Paul Novitski

At 1/26/2007 12:25 PM, Otto Wyss wrote:

Paul Novitski wrote:
In both cases I store the text in database tables that contain a 
language field I can select on to match the user's request.


I wonder if retrieving static texts from the database draws too much 
performance. I know from somebody who stores texts in large data 
arrays an uses shared memory, yet I haven't figured it out how.


I consider storing static texts as defines and just load a different 
definition file when the user switches language. Is this practical?



If you store your text in a data table and retrieve it with a query, 
you're leaning your weight on SQL (or your database engine of choice).


If you store your text in individual text files, you're leaning on 
the operating system's own database system to locate, open, and read the file.


If you store all your text in a single text file, you're leaning on 
server memory to store everything when you may only want a few chunks.


Unless your site is insanely popular or huge, does the method really 
matter so much?  The idea of storing all the text for an entire 
website in a single text file sounds scary but feasible if the site 
size is modest.  Servers and database engines are built to perform 
file I/O quickly  efficiently, and I find it unlikely that you'll 
strain the system unless your traffic is enormous, your content huge, 
and your queries inefficient.


Is your static text really static?  How often is it modified?  If 
you're really concerned about streamlining, consider building your 
pages dynamically from a database but then caching them on the server 
as plain html, refreshing individual files in the cache when your 
SQL-based content changes.


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



[PHP] Creating an array as a property of an object

2007-01-26 Thread Ken Kixmoeller -- reply to [EMAIL PROTECTED]

Hello, folks -- lurking for a while, first post --

I'm relatively new to PHP but doing database design work for nearly  
20 years.


I've RTFM'ed (+ books + other resources) a bunch of times but I have  
a mental block around doing this:


I want to have an multidimensional array as a property of an object.

Example:

MySQL Resource:
 WHAM_ID  NAME AMOUNT
  5   Fred 99
  9   Albert  345
 23   Mary  5
 (etc...)

Inside the function which builds the instance of the object, I have  
language like:


while ($line = mysql_fetch_array($result_set,MYSQL_ASSOC))
{
  $this-foom_array = array(MyKey.$line[wham_id]=array($line).,;
}
This isn't even close. g

Any examples, or a well-written resource to help me do this?

TIA

Ken

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



Re: [PHP] Creating an array as a property of an object

2007-01-26 Thread Robert Cummings
On Fri, 2007-01-26 at 15:09 -0600, Ken Kixmoeller -- reply to
[EMAIL PROTECTED] wrote:
 Hello, folks -- lurking for a while, first post --
 
 I'm relatively new to PHP but doing database design work for nearly  
 20 years.
 
 I've RTFM'ed (+ books + other resources) a bunch of times but I have  
 a mental block around doing this:
 
 I want to have an multidimensional array as a property of an object.
 
 Example:
 
 MySQL Resource:
   WHAM_ID  NAME AMOUNT
5   Fred 99
9   Albert  345
   23   Mary  5
   (etc...)
 
 Inside the function which builds the instance of the object, I have  
 language like:
 
 while ($line = mysql_fetch_array($result_set,MYSQL_ASSOC))
 {
$this-foom_array = array(MyKey.$line[wham_id]=array($line).,;

$this-foom_array[$line['WHAM_ID']] = $line;

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



Re: [PHP] Creating an array as a property of an object

2007-01-26 Thread Ken Kixmoeller -- reply to [EMAIL PROTECTED]


On Jan 26, 2007, at 3:08 PM, Robert Cummings wrote:


$this-foom_array[$line['WHAM_ID']] = $line;

Cheers,
Rob.


Thank you so much, Rob. That did it. (Kickin' the cobwebs out of my  
head...)


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



Re: [PHP] Ongoing encoding issues

2007-01-26 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-01-26 21:09:34 +:
 # [EMAIL PROTECTED] / 2007-01-26 09:33:13 +:
  Hi all, I posted a question a couple of days ago regarding a web app I have
  wherein users are able to indicated prices and concessions via a text field,
  and the resulting encoding issues I have experienced, the main one being
  seeing the pound sign as Â? if viewing the results in a browser with the
  encoding set to Latin-1.
 
 Your PostgreSQL database uses some encoding,

Dave pointed out to me that he's using MySQL.  That means the
configuration mechanisms for the database will be different, but the
principal issue remains the same.

 your PHP script runs under some locale (incl. character encoding), and
 the browser sent the text in some encoding.  PostgreSQL assumes the
 input data is in the charset the database uses (unless you have
 client_encoding set in postgresql.conf, or PGCLIENTENCODING (IIRC) in
 the environment, or have set client_encoding using the SET command).
 
 It's important that you correctly identify encoding of the inserted data
 to PostgreSQL or convert it to the encoding it expects beforehand.  You
 can use iconv or recode functions in PHP, I'd probably have a look if
 there's an apache input filter for character encoding conversions.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



[PHP] Result sorting not working

2007-01-26 Thread Dan Shirah

I have a search page that displays all active records in my application, but
for some reason, I can not get it to display based on a specific input.

For instance, I have records with id's 2, 3, 4, 5 etc...  In my search form,
the default view shows all records, and my form variable lets you put in
different search criteria.  If I do a search by id and put in 2 as the
search condition, my results keep coming back blank.  It does not matter
which parameter or value I put in, it still returns blank.

Any ideas?

?php
$connection = mssql_connect($host, $user, $pass) or die ('server connection
failed');
 $database = mssql_select_db($database, $connection) or die ('DB
selection failed');


 // Query the table and load all of the records into an array.
 $query = SELECT
child_support_payment_request.credit_card_id,
  credit_card_payment_request.credit_card_id,
  credit_card_payment_request.date_request_received
   FROM child_support_payment_request,
credit_card_payment_request
 WHERE child_support_payment_request.credit_card_id =
credit_card_payment_request.credit_card_id;
if ($request_id !== '') {
   $query.= AND credit_card_payment_request.credit_card_id =
$request_id2;
   }
if ($dateTime !== '') {
  $query.= AND credit_card_payment_request.date_request_received =
$dateTime2;
  }
$res = mssql_query($query) or die(mssql_error());


 echo table width='780' border='1' align='center' cellpadding='2'
cellspacing='2' bordercolor='#00';

while ($rows = mssql_fetch_array($res)) {
  $res_id = $rows['credit_card_id'];
  $res_dateTime = $rows['date_request_received'];
echo tr;
echo td width='88' height='13' align='center' class='tblcell'div
align='center'$res_id/div/td;
echo td width='224' height='13' align='center' class='tblcell'div
align='center'$res_dateTime/div/td;
echo td width='156' height='13' align='center' class='tblcell'div
align='center'Open/div/td;
echo td width='156' height='13' align='center' class='tblcell'div
align='center'Payment Type/div/td;
echo td width='156' height='13' align='center' class='tblcell'div
align='center'Last Processed By/div/td;
echo /tr;
}
echo /table;
?


The variables $request_id and $dateTime are specified in a seperate chunk of
php code, but are still included on the same page as the code below.  Am I
right in assuming that any variable set on the same page can be carried into
different php blocks on the same page?

Example:

?php

$id = $_POST['request_id']

?

?php

echo table;
echo td'
echo $id;
echo /td;
echo /table;

?

That would be valid, correct?


Re: [PHP] PHP with XML database

2007-01-26 Thread Bernhard Zwischenbrugger
Hi

Some questions

 As part of my research under my professor I have to implement a web 
 interface to their benchmarking data.
 
 PHP is the chosen web language but we are little worried about the 
 database. The benchmark data comes to us in XML format (e.g. 
 http://www.matf.bg.ac.yu/~filip/ArgoLib/smt-lib-xml/Examples/FolEq1.xml).
 We have to implement an interface to query them, get data, update etc.

You can parse the XML, extract the data, put it to an SQL DB and move
the XML to /dev/null (delete it).
If you do that, you don't need an XML DB.
Is this possible?

 
 We even can change schema in the form of attributes. . The data size 
 would be around 100 MB each XML with around 100 different XMLs.

What do you mean by different XMLs?
Are you looking for a maschine that makes SQL Tables from XML?
What is inside of the 100MB XML? Your example is a MathML Formula.

 
 The load would be max 5-10 users any given time, batch updates once a 
 month and heavy load probably 2-3 times a month. Mission criticality is 
 not important, we can get it down sometimes. Which db would you suggest?
 
 I did Google research and as of now - I like eXist, Sedna (they seem to 
 have good PHP wrapper support) and Timber. Another thing would be good 
 documentation and support.

With an XML DB you can query data using XPATH. Is that the thing you
want? Oracle supports that for example.

Bernhard

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



[PHP] Can a class instance a property of another class

2007-01-26 Thread Ken Kixmoeller -- reply to [EMAIL PROTECTED]

Hey - --  -

Here I am again. Anybody still working on a Friday?

I would like to have a class instance be the property of another  
class, like can be done in other languages. For example: I would like  
to have a Connections class which contains all of the database  
connection logic and query results. There are advantages to having  
this type of utility class be local to a data or business class. (I  
know that I could have a generic include with functions outside of  
the class hierarchy.)


So, in the __construct method of a business or data class, for  
example, one could:


include_once(connection_classes.kbk);
$this-connection_class = new connection_class;

This syntax fails, so I know this isn't right, but I hope you get the  
idea.


Can it be done?

TIA, again

Ken

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread Larry Garfield
I have long since given up on raw insert/update/delete statements as the 
syntax is all kinds nasty.  These days I just do this, which is even easier 
and more powerful:

http://www.garfieldtech.com/blog/simplifying-sql

On Friday 26 January 2007 10:03 am, [EMAIL PROTECTED] wrote:
 My contribution to the insanity..  INSERT statements made easy:

 $genericQY  = INSERT INTO MOD_LMGR_Leads (;  $genericQYvalues  =  VALUES
 (; $genericQY .=  FirstName,;   $genericQYvalues .= 
 'John',; $genericQY .=  LastName; $genericQYvalues
 .=  'Smith'; $genericQY .=  );   
 $genericQYvalues .=  );; $genericQY .= $genericQYvalues;
 $genericRS = mysql_query($genericQY);


 I use this structure so if I decide that I don't need certain data I can
 comment out a single line to remove the column name and corresponding
 value.  Also helpful for making updates to column/value pairs and not worry
 about the dreaded error involve # of columns not matching.

 Only things you have to watch for:

 1. Make sure you don't have a comma on the last item
 2. Make sure you have spaces where appropriate so when it concatenates the
 strings, you don't get stuff crammed together (not really an issue with the
 INSERT statement, but I try to keep a consistant practice with all my
 queries so I don't slip up..   SELECT columnsFROM tableWHERE something =
 something is where it really gets ya if you forget spaces.. just as an
 example) 3. Make sure to remember to concatenate the query and values
 parts

 I like to think this is a little outside the box thinking since common
 practice is one command, one line or total chaos hah.

 Any comments on improving this or other unique stylistic ways people like
 to design their code?

 -TG


 = = = Original message = = =

 On Wed, January 24, 2007 8:07 pm, Robert Cummings wrote:
  On Wed, 2007-01-24 at 18:23 -0600, Richard Lynch wrote:
  On Wed, January 24, 2007 7:41 am, Roman Neuhauser wrote:
   # [EMAIL PROTECTED] / 2007-01-24 13:57:03 +0200:
   and also in these days I'm looking for 19 inch (or more) wide LCD
   sceerns to able to fit longer lines in my screen...
  
   Number of reading errors people make grows with line length,
   this has been known for as long as I remember.  You're increasing
 
  the
 
   probability of bugs in the code, and get tired sooner because
   following
   long lines requires more energy.
 
  I believe those results are specific to what is being read.
 
  Surely it's easier to read:
 
  SELECT blah, blah, blah, blah, blah, blah, blah, blah, blah
 
  if it's all on one line, no matter how many fields there are, while
  trying to read the code as a whole.
 
  Sure, it can be hard to find/read the individual field names, on
  the
  rare occasion that you need to do that...
 
  Dear Mr Lynch, normally I highly respect your commentary on the list,
  but today I think you've been-a-smoking the crackpipe a tad too much.
 
  There is no way in hell one long line of SQL is easier to read than
  formatted SQL that clearly delineates the clause structure.
 
  SELECT A.field1 AS afield1, A.field2 AS afield2, B.field1 AS bfield1,
  B.field2 AS bfield2, C.field1 AS cfield1, C.field2 AS cfield2,
  D.field1
  AS dfield1, D.field2 AS dfield2 FROM tableA as A LEFT JOIN tableB AS B
  ON B.fee = A.foo LEFT JOIN tableC AS C ON C.fii = B.fee LEFT JOIN
  tableD
  AS D ON D.fuu = C.fii WHERE A.foo = 'someValue' ORDER BY afield1 ASC,
  cfield2 ASC
 
  The above line should be on one line, but my email client might
  autowrap it. Either way, the following is formatted and is much
  clearer.
 
  SELECT
  A.field1 AS afield1,
  A.field2 AS afield2,
  B.field1 AS bfield1,
  B.field2 AS bfield2,
  C.field1 AS cfield1,
  C.field2 AS cfield2,
  D.field1 AS dfield1,
  D.field2 AS dfield2
  FROM
  tableA as A
  LEFT JOIN tableB AS B ON
  B.fee = A.foo
  LEFT JOIN tableC AS C ON
  C.fii = B.fee
  LEFT JOIN tableD AS D ON
  D.fuu = C.fii
  WHERE
  A.foo = 'someValue'
  ORDER BY
  afield1 ASC,
  cfield2 ASC
 
 
  While the above is contrived, most of us know such examples happen
  quite
  often in the wild. Not only is it easier to read, but the task of
  adding
  or removing selected fields is trivial.

 I meant ONLY the SELECT part on a single line.

 Only a moron would cram the FROM and all that into the same line.

 :-)

 $query = SELECT blah1, blah2, blah3, ... blah147 ;
 $query .=  FROM table1 ;
 $query .=  LEFT OUTER JOIN table2 ;
 $query .= ON blah7 = blah42 ;
 $query .=  WHERE blah16 ;
 $query .=AND blah42 ;
 $query .=  ORDER BY blah9, blah8 desc, blah6 ;

 is what I go for.

 The SELECT line is the only one that ever gets all that long, really...

 --
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some starving artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?

 

[PHP] PHP Flash

2007-01-26 Thread Skip Evans

Hey all,

We have a new project that will require pretty 
robust communication between Flash and PHP, and 
I've begun Googling and came across Actionscript here:


http://www.adobe.com/devnet/flash/articles/flashmx_php.html

I wonder if anyone knows anything about running 
actionscript on LinuxFfirfox machines. My install 
of Firefox on Debian/Fluxbox runs Flash okay, but 
not the sample app on this page.


The page above had a zip file that may need to be 
downloaded to your Windows machine, but my Windows 
machine ran it fine.


Anyone have any experience with PHP/Actionscript 
on Linux?


Thanks!
--
Skip Evans
Big Sky Penguin, LLC
61 W Broadway
Butte, Montana 59701
406-782-2240
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=

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



RE: [PHP] Can a class instance a property of another class

2007-01-26 Thread Jay Blanchard
[snip]
I would like to have a class instance be the property of another  
class, like can be done in other languages. For example: I would like  
to have a Connections class which contains all of the database  
connection logic and query results. There are advantages to having  
this type of utility class be local to a data or business class. (I  
know that I could have a generic include with functions outside of  
the class hierarchy.)

So, in the __construct method of a business or data class, for  
example, one could:

include_once(connection_classes.kbk);
$this-connection_class = new connection_class;

This syntax fails, so I know this isn't right, but I hope you get the  
idea.

Can it be done?
[/snip]

Extends?

class new_connection extends connection {}

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



RE: [PHP] Can a class instance a property of another class

2007-01-26 Thread Jay Blanchard
[snip]
This syntax fails, so I know this isn't right, but I hope you get the  
idea.

Can it be done?
[/snip]

Extends?

class new_connection extends connection {}
[/snip again]

I read too fast

A member function can be referenced by another class as long as the
function is public. You would just use it within the class as you would
call any member function.

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



Re: [PHP] Can a class instance a property of another class

2007-01-26 Thread Jochem Maas
Ken Kixmoeller -- reply to [EMAIL PROTECTED] wrote:
 Hey - --  -
 
 Here I am again. Anybody still working on a Friday?
 
 I would like to have a class instance be the property of another class,
 like can be done in other languages. For example: I would like to have a
 Connections class which contains all of the database connection logic
 and query results. There are advantages to having this type of utility
 class be local to a data or business class. (I know that I could have a
 generic include with functions outside of the class hierarchy.)
 
 So, in the __construct method of a business or data class, for example,
 one could:
 
 include_once(connection_classes.kbk);
 $this-connection_class = new connection_class;
 
 This syntax fails, so I know this isn't right, but I hope you get the idea.

what fails? I can't smell the error your getting from here and from what I see
there should be no problem:

class Foo
{
private $var;
function __construct() { $this-var = foo; }
function getFoo() { return $this-var; }
}

class Bar
{
private $var;
private $foo;
function __construct() { $this-var = bar; $this-foo = new Foo; }
function getBar() { return $this-var; }
function speak() { echo I am 
,$this-foo-getFoo(),$this-getBar(),\n; }
}

$b = new Bar;
$b-speak();

 
 Can it be done?

yes. see above. :-)

 
 TIA, again
 
 Ken
 
 --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



Re: [PHP] Can a class instance a property of another class

2007-01-26 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-01-26 17:18:37 -0600:
 So, in the __construct method of a business or data class, for  
 example, one could:
 
 include_once(connection_classes.kbk);
 $this-connection_class = new connection_class;
 
 This syntax fails, so I know this isn't right, but I hope you get the  
 idea.

And we have to guess the error message? I don't see anything wrong
with the syntax. Post a small but complete script, and the error message.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] PHP Flash

2007-01-26 Thread Jochem Maas
Skip Evans wrote:
 Hey all,
 
 We have a new project that will require pretty robust communication
 between Flash and PHP, and I've begun Googling and came across
 Actionscript here:
 
 http://www.adobe.com/devnet/flash/articles/flashmx_php.html
 
 I wonder if anyone knows anything about running actionscript on
 LinuxFfirfox machines. My install of Firefox on Debian/Fluxbox runs
 Flash okay, but not the sample app on this page.

probably because the flash player version on your machine is
too old?

 
 The page above had a zip file that may need to be downloaded to your
 Windows machine, but my Windows machine ran it fine.
 
 Anyone have any experience with PHP/Actionscript on Linux?

wtf?

PHP runs on the webserver, actionscript run inside a Flash 'object' which
itself runs in the webbrowser on the client.

the communication between flash and php is via our friend HTTP.
flash makes requests to the webserver just as the browser would and the
requested scripts on the webserver stip out data (usually XML) back to
flash ... you use actionscript code inside flash to make the request and
parse the returned data.

flash is platform independent - you create a flash file with actionscript code 
in
it (and whatever else is relevant, in terms of animation, etc), you compile it 
into
an SWF file and that file weill run in any browser with a flash player (with the
caveat that some flash functionality is only available in newer version of
the flash player.

 
 Thanks!

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



Re: [PHP] PHP with XML database

2007-01-26 Thread Ritesh Nadhani

Hello

Bernhard Zwischenbrugger wrote:

Hi

Some questions

As part of my research under my professor I have to implement a web 
interface to their benchmarking data.


PHP is the chosen web language but we are little worried about the 
database. The benchmark data comes to us in XML format (e.g. 
http://www.matf.bg.ac.yu/~filip/ArgoLib/smt-lib-xml/Examples/FolEq1.xml).

We have to implement an interface to query them, get data, update etc.


You can parse the XML, extract the data, put it to an SQL DB and move
the XML to /dev/null (delete it).
If you do that, you don't need an XML DB.
Is this possible?



No. My professor is dead against that. Many people have suggested me 
doing that. Why? Are XML databases incorrectly implemented or are bad?


We even can change schema in the form of attributes. . The data size 
would be around 100 MB each XML with around 100 different XMLs.


What do you mean by different XMLs?
Are you looking for a maschine that makes SQL Tables from XML?
What is inside of the 100MB XML? Your example is a MathML Formula.



By different XMLs I meants, different XML files. So we can have 40 XML 
files with around 50-100 MB each.


Yes, they will have lot sof those MathML formulas. Its benchmarking data 
from some theoritical group that my professor works with. They have all 
their database in XML so relational database is not possible otherwise 
we will have to convert them between XML and relational all the time.


The load would be max 5-10 users any given time, batch updates once a 
month and heavy load probably 2-3 times a month. Mission criticality is 
not important, we can get it down sometimes. Which db would you suggest?


I did Google research and as of now - I like eXist, Sedna (they seem to 
have good PHP wrapper support) and Timber. Another thing would be good 
documentation and support.


With an XML DB you can query data using XPATH. Is that the thing you
want? Oracle supports that for example.



Yeah but looking at 
http://www.oracle.com/technology/tech/xml/xmldb/index.html, I could not 
find whether its free. I might be wrong but the info is not easily found 
there.


One the contrary IBMs offering at 
http://www-306.ibm.com/software/data/db2/express/download.html looks FREE.


The problem is that both the above two database are beasts in themselves 
and I just require 10% of what they do :)


We looked into Berkeley DB also but their support for PHP is not that 
great. We have compile the module by ourselves etc (this is not a 
problem though as we have the technical know how to do that) but lot of 
people have suggested that its not a very stable system. I have not done 
any benchmarking on it but I dont want to change my underlying DB couple 
of months down the line just because we found out its not stable.


Apart from the above big three, the other free and reasonable good 
implementation seems to be eXist, Timber and Sedna. This I am just 
saying by reading their website. I have not used them.


So my question is: out of the six systems listed above, which one you 
would suggest? Has anybody used any of the above system before? What are 
your experiences?



Bernhard



Ritesh






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



Re: [PHP] Multi lingual pages

2007-01-26 Thread Jochem Maas
Otto Wyss wrote:
 Paul Novitski wrote:
 
 I formulated my question in general since I couldn't find an other
 message here about supporting multiple languages.
 
 http://www.w3.org/International/articles/

 http://www.w3.org/TR/i18n-html-tech-lang/

 http://php.net/setlocale

 Thanks a lot, these are good points for reading.

 1) Switching language downloads a new version of the current page,
 generally with the same markup but new text.  Example:
 http://partcon.ca/

 I'll favor this way especially if several languages have to be provided.
 
 In both cases I store the text in database tables that contain a
 language field I can select on to match the user's request.

 I wonder if retrieving static texts from the database draws too much
 performance. I know from somebody who stores texts in large data arrays
 an uses shared memory, yet I haven't figured it out how.
 
 I consider storing static texts as defines and just load a different
 definition file when the user switches language. Is this practical?

don't go down the define('LANG_KEY', 'lang string value'); route - defines
are comparatively SLOW to create. IF you go down the road of loading in text
from 'per lang' files I would suggest using an array as the storage mechanism:

$Lang = array(
'LANG_KEY' = 'lang string value',
// .. etc
);

assoc array are much less heavy to create.

also consider that there are, imho, 2 kinds of language specific data:

1. 'static' values - button texts, [error] messages - these are specified 
during site/application
design.

2. 'dynamic' values - document titles, headers, content - these are specified 
by the owner/user during
the lifetime of the site/application

for the rest I'll just say 'ditto' to most of what the other list members 
replied :-)

 
 O. Wyss
 

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



Re: [PHP] PHP Flash

2007-01-26 Thread Skip Evans

Jochem Maas wrote:

Anyone have any experience with PHP/Actionscript on Linux?



wtf?


Oh my God. What am I thinking? Please folks, I am 
really not this stupid. It has been too, too long 
a day. Yes, I just need to upgrade Flash on this 
workstation.


Skip
--
Skip Evans
Big Sky Penguin, LLC
61 W Broadway
Butte, Montana 59701
406-782-2240
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=

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



Re: [PHP] PHP with XML database

2007-01-26 Thread Bernhard Zwischenbrugger
Hi again

I don't know what the DB should do for you.

If you simple want to select subtrees from your big XML, you can put
the XML Files to the filesystem and use XPointer for query.

Here an example:

?php
$xml=END
result xmlns:xi=http://www.w3.org/2001/XInclude; 
xmlns:xhtml=http://www.w3.org/1999/xhtml;
xi:include 
href=http://www.laptop.org/vision/index.shtml#xmlns(xhtml=http://www.w3.org/1999/xhtml)xpointer(//xhtml:div[1]//xhtml:div[1])
 parse=xml
   xi:fallback
   errornot found/error
   /xi:fallback
  /xi:include
/result
END;

$dom=domDocument::loadXML($xml);
$dom-xinclude();

header(Content-type:text/xml);
echo $dom-saveXML();
?

This example loads an XML (xhtml) from the web (filesystem is also
possible) and outputs a subtree of the document.
The subtree is selected by an XPointer expression.

The XML: http://www.laptop.org/vision/index.shtml
The XPointer:
#xmlns(xhtml=http://www.w3.org/1999/xhtml)xpointer(//xhtml:div[1]//xhtml:div[1])
(the namespace part is a little tricki)

To parse 100MByte takes some time.
A database can improve speed, the query syntax (XPointer) maybe is the
same.
Without knowing what the output of the database should be und the query
parameters, it is not easy to tell what db is the best for you.

A solution could be to split the 100MByte file in small parts and store
the subtrees to blobs in mySql. You can build an index based on XPath
and it could be a real fast solution.



Bernhard



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



[PHP] Create ACH Origination file with PHP

2007-01-26 Thread Dan Harrington

Hello,

Does anyone know of a script that can create an ACH origination file with 
PHP?


Thanks
Dan

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



[PHP] connect.c+php

2007-01-26 Thread ed gregory

Can anyone give me an example on using connect.c with php?

Thank you.

Ed

--
http://www.freenet.am/

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



[PHP] cennect.c+php

2007-01-26 Thread Eduard Grigoryan

Can anyone give me an example on using connect.c with php?

Thank you.

Ed

--

Armenian Freenet Catalog
http://freenet.am/~edik_g
http://armfn.net/~edik_g


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