Re: [PHP] Friday's Question

2013-09-20 Thread Mattias Thorslund

40, and no mouse pad atm. Seems that this table top is okay.

This is an optical mouse without a ball underneath. However this 
mac-y-mouse DOES have a ball on top, for scrolling.


Go figure.

Mattias

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



Re: [PHP] A relative date puzzle

2013-04-01 Thread Mattias Thorslund

On 4/1/13 11:05 AM, Jim Giner wrote:
I'm looking for some ideas on how to handle the following get a 
datetime value that is relative to a specific future date when 
presented with a partial day time value.


Specifically, I have an appl that requires some lengthy input 
involving days and times.  I have streamlined the d/e effort so that 
it can be done entirely using the number keypad (if available), or 
else just with numeric entries.  Works great, very quick (JS) and 
accurate.  Basically the users type some numbers and end up with 
something like:


Sat 08:00am  or Fri 07:00pm etc.

Does anyone have an idea on how I can convert this value to a true 
datetime value for my database updates, where the above value is 
relative to a specific date in the future?  IE, the d/e takes place a 
few days before a certain upcoming date and I want my entry of Sat 
to translate to the Saturday following that certain date.  This could 
take place one to two weeks prior to the start date, so just adding 
next to the value above won't work.  I really need to incorporate a 
specific date in the solution.


Thoughts anyone?




Use strtotime() to get a UNIX time stamp, then use date() to format it 
as you like.


$myDate = strtotime(wed 11:00 am); //1365012000
echo date(Y-m-d H:i:s, $myDate); //2013-04-03 11:00:00

On two lines for clarity.

Cheers,

Mattias

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



Re: [PHP] A relative date puzzle

2013-04-01 Thread Mattias Thorslund

On 4/1/13 11:15 AM, Mattias Thorslund wrote:

On 4/1/13 11:05 AM, Jim Giner wrote:
I'm looking for some ideas on how to handle the following get a 
datetime value that is relative to a specific future date when 
presented with a partial day time value.


Specifically, I have an appl that requires some lengthy input 
involving days and times.  I have streamlined the d/e effort so that 
it can be done entirely using the number keypad (if available), or 
else just with numeric entries.  Works great, very quick (JS) and 
accurate.  Basically the users type some numbers and end up with 
something like:


Sat 08:00am  or Fri 07:00pm etc.

Does anyone have an idea on how I can convert this value to a true 
datetime value for my database updates, where the above value is 
relative to a specific date in the future?  IE, the d/e takes place a 
few days before a certain upcoming date and I want my entry of Sat 
to translate to the Saturday following that certain date.  This could 
take place one to two weeks prior to the start date, so just adding 
next to the value above won't work.  I really need to incorporate a 
specific date in the solution.


Thoughts anyone?




Use strtotime() to get a UNIX time stamp, then use date() to format it 
as you like.


$myDate = strtotime(wed 11:00 am); //1365012000
echo date(Y-m-d H:i:s, $myDate); //2013-04-03 11:00:00

On two lines for clarity.

Cheers,

Mattias



I'm sorry, I didn't read the last part of your question too closely.

strtotime() should help you there as well. Just put the timestamp of the 
date to compare the string expression to as the second parameter.


$relativeToDate = strtotime(2013-04-04); //1365058800
$myDate = strtotime(wed 11:00 am, $relativeToDate); //1365616800
echo date(Y-m-d H:i:s, $myDate); //2013-04-10 11:00:00

For more advanced date manipulation, there are the Date/Time functions 
but this is simple stuff. You can even do it OO-style with the DateTime 
class  Co.


Cheers,

Mattias

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



[PHP] crash dump on OS X Server: PHP / Apache

2012-10-09 Thread Mattias Thorslund

Perhaps someone can read this backtrace.

This is a problem that causes Apache to not send any output at all. 
Doing a die() just before one particular require_once prevents the 
issue. If I move that die() into the required file and place it just 
after the opening PHP tag, I get the error again. I have verified the 
PHP syntax of this file with php -l .


This site uses CodeIgniter and FileMaker's PHP API, and the include file 
where this happens is one of the API files. The PHP library is the one 
supplied by FileMaker 12 Advanced Server. Another PHP application on the 
same server, using the same FileMaker API is running just fine, but that 
one isn't using CodeIgniter.


Any insight would be greatly appreciated.

Mattias

Process: httpd [9018]
Path:/usr/sbin/httpd
Identifier:  httpd
Version: ??? (???)
Code Type:   X86-64 (Native)
Parent Process:  httpd [7101]

Date/Time:   2012-10-09 17:57:11.216 -0700
OS Version:  Mac OS X Server 10.6.8 (10K549)
Report Version:  6

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libphp5.so  0x00010131fe1c _zend_mm_alloc_int + 
924
1   libphp5.so  0x000101332d4b init_op_array + 113
2   libphp5.so  0x000101319be7 compile_file + 218
3   libphp5.so  0x000101196ec1 phar_compile_file + 
844
4   libphp5.so  0x00010131923b compile_filename + 
190
5   libphp5.so  0x00010136925d 
ZEND_INCLUDE_OR_EVAL_SPEC_TMP_HANDLER + 714
6   libphp5.so  0x00010135f6b9 execute + 585
7   libphp5.so  0x000101330f7c zend_call_function + 
2223
8   libphp5.so  0x00010133199a 
call_user_function_ex + 76
9   libphp5.so  0x00010133b856 zend_error + 1794
10  libphp5.so  0x00010130e216 zendparse + 8810
11  libphp5.so  0x000101319bfb compile_file + 238
12  libphp5.so  0x000101196ec1 phar_compile_file + 
844
13  libphp5.so  0x0001013691d8 
ZEND_INCLUDE_OR_EVAL_SPEC_TMP_HANDLER + 581
14  libphp5.so  0x00010135f6b9 execute + 585
15  libphp5.so  0x000101330f7c zend_call_function + 
2223
16  libphp5.so  0x000101261feb 
zif_call_user_func_array + 111
17  libphp5.so  0x0001013600ab 
zend_do_fcall_common_helper_SPEC + 2401
18  libphp5.so  0x00010135f6b9 execute + 585
19  libphp5.so  0x00010133a8c4 zend_execute_scripts 
+ 376
20  libphp5.so  0x0001012ebf95 php_execute_script + 
732
21  libphp5.so  0x0001013b7612 php_handler + 1237
22  httpd   0x000112cf ap_run_handler + 90
23  httpd   0x00011bc8 ap_invoke_handler + 
354
24  httpd   0x00010002ebd0 ap_process_request + 
103
25  httpd   0x00010002b3b4 
ap_process_http_connection + 116
26  httpd   0x0001000128ac 
ap_run_process_connection + 90
27  httpd   0x000100012d7a 
ap_process_connection + 91
28  httpd   0x000100035fbe child_main + 1257
29  httpd   0x00010003617d make_child + 329
30  httpd   0x000100036403 
perform_idle_server_maintenance + 498
31  httpd   0x00010003692d ap_mpm_run + 1246
32  httpd   0x000198f4 main + 2868
33  httpd   0x00010934 start + 52

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x  rbx: 0x000d  rcx: 0x  
rdx: 0x0359
  rdi: 0x0002  rsi: 0x000101d00950  rbp: 0x7fff5fbfc3f0  
rsp: 0x7fff5fbfc3b0
   r8: 0x00010087f8f0   r9: 0x000c  r10: 0x0001  
r11: 0x000101d6c5b0
  r12: 0x000101d00928  r13: 0x000101d00928  r14: 0x00010087f200  
r15: 0x1e10
  rip: 0x00010131fe1c  rfl: 0x0206  cr2: 0x

Binary Images:
   0x1 -0x10004bfe7 +httpd ??? (???) 
36669387-22E7-3D70-2384-46243282B4CC /usr/sbin/httpd
   0x10007f000 -0x1000a7ff7  libpcre.0.dylib 1.1.0 (compatibility 1.0.0) 
61E04B84-398D-0E87-7125-A668E797DE77 /usr/lib/libpcre.0.dylib
   0x1000ac000 -0x1000c4fe7  libaprutil-1.0.dylib 4.9.0 (compatibility 
4.0.0) 

Re: [PHP] Help on number matching function

2011-09-16 Thread Mattias Thorslund
If one or both of your data sets are in MySQL already, there may be no 
need to do the comparison in PHP. Just use IN() or INNER JOIN. Or is 
there some particular reason why neither of these will work in your case?


Cheers,

Mattias

On 09/16/2011 05:36 AM, Dare Williams wrote:

Dear PHP Group,

I need a Function of any category in  either PHP or MySQL RDBMS customize 
Function, Class, Methods or anything that could help me compare a particular 
set of number and return their matching result. e.g If I have a 5 Digits set of 
number  and need to match it with another set of five  digits and return how 
many number are match and the figures that are match.

1.(62,39,47,25,14) - (14,39,62,25,47) - match 5 (all)
2.(55,11,27,62,39) - (66,39,12,13,27) - match 2 (27,39)
3.(20,04,56,17,16) - (16,01,17,04,79) - match 3 (16,17,04)

Any Help will be appreciated.

Thank you.





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



Re: [PHP] How to PHP get bit depth of a given PNG image file?

2011-06-16 Thread Mattias Thorslund

On 06/15/2011 10:11 PM, Nam Gi VU wrote:

  Hi everyone,

In PHP code, given an .png image path, I need to detect the bit-depth of
that image. How can I do that?

I've tried to use getImageSize() and read the bits as below sample code but
it always returns '8' for 24-bits/32-bits image.


Reading the manual, it says:


channels will be 3 for RGB pictures and 4 for CMYK pictures.
bits is the number of bits for each color.


So, to get the total bit depth, I think you need to multiply by the 
number of colors, which is in the channels element.


Cheers,

Mattias


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



Re: [PHP] How to PHP get bit depth of a given PNG image file?

2011-06-16 Thread Mattias Thorslund
I think the documentation is a bit unclear about the fact that colors 
and channels are the same thing here. The line about bits should 
probably say bits is the number of bits for each *channel*.


Mattias

On 06/15/2011 11:11 PM, Nam Gi VU wrote:

Thank you Mattias,

I'll look at `channels` again.

Regards,
Nam



On Thu, Jun 16, 2011 at 1:06 PM, Mattias Thorslundmatt...@thorslund.uswrote:


On 06/15/2011 10:11 PM, Nam Gi VU wrote:


  Hi everyone,

In PHP code, given an .png image path, I need to detect the bit-depth of
that image. How can I do that?

I've tried to use getImageSize() and read the bits as below sample code
but
it always returns '8' for 24-bits/32-bits image.


Reading the manual, it says:


channels will be 3 for RGB pictures and 4 for CMYK pictures.
bits is the number of bits for each color.


So, to get the total bit depth, I think you need to multiply by the number
of colors, which is in the channels element.

Cheers,

Mattias


--
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] floored by floor()

2010-10-14 Thread Mattias Thorslund

On 10/13/2010 11:56 PM, gaojian wrote:

在 2010-10-13三的 22:48 -0700,Mattias Thorslund写道:
   

Hi List,

I'm having a problem with the behavior of the floor() function:

echo floor(327.03 * 100).\n; //prints 32702 and not 32703!!

Sanity check:
var_dump(327.03 * 100); //prints float(32703) as expected

Any ideas why this happens, and how to work around it?

Thanks,

Mattias


 

i think u should read the manual about int and float:

http://www.php.net/manual/en/language.types.integer.php

http://www.php.net/manual/en/language.types.float.php#warn.float-precision


jim
   


Thanks, I guess I needed to read that again. What confused me here was 
that var_dump(327.03 * 100) returns the expected value and not something 
like (float)32702.99...


Cheers,

Mattias


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



Re: [PHP] floored by floor()

2010-10-14 Thread Mattias Thorslund

On 10/13/2010 11:14 PM, Glen Fuller wrote:

On 10/13/2010 10:48 PM, Mattias Thorslund wrote:

Hi List,

I'm having a problem with the behavior of the floor() function:

echo floor(327.03 * 100).\n; //prints 32702 and not 32703!!

Sanity check:
var_dump(327.03 * 100); //prints float(32703) as expected

Any ideas why this happens, and how to work around it?

Thanks,

Mattias




Wouldn't that be equivalent to floor(32703), and since 32703 is the 
nearest integer to 32703 it returns it?


Glen Fuller


Nope, this is floating-point math fuzziness. Try it:

echo floor(32703).\n;
echo floor(327.03 * 100).\n;

Cheers,

Mattias

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



[PHP] floored by floor()

2010-10-13 Thread Mattias Thorslund

Hi List,

I'm having a problem with the behavior of the floor() function:

echo floor(327.03 * 100).\n; //prints 32702 and not 32703!!

Sanity check:
var_dump(327.03 * 100); //prints float(32703) as expected

Any ideas why this happens, and how to work around it?

Thanks,

Mattias


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



Re: [PHP] Sort two coupled arrays

2010-04-07 Thread Mattias Thorslund

Piero Steinger wrote:

Am 07.04.2010 22:09, schrieb tedd:
  

Hi gang:

Here's the problem -- I want to sort and combine two arrays into one
sorted array. Here's a real-world example:

Array 1
(
[1] = 75
[2] = 31
[3] = 31
[4] = 31
[5] = 40
)

Array 2
(
[1] = Personal Email
[2] = Personal Phone
[3] = Web site
[4] = Text Message
[5] = USPS mail
)

After the operation, I want this:

Array
(
[75] = Personal Email
[40] = USPS mail
[31] = Personal Phone
[31] = Web site
[31] = Text Message
)

Note: This is a descending-sort of Array 1 while being coupled to
index of Array 2. In other words, the order of Array 2 depends upon
the order of Array 1 -- the two arrays are coupled.

I've solved this problem, but my solution is pretty lame. There has to
be a better/slicker way.

Suggestions?

Cheers,

tedd




array_combine($key_array, $value_array)
 
:)


-- Piero
  


And then:

krsort($combined_array);


Cheers,

Mattias

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



Re: [PHP] any reason *not* to use PEAR DB module when accessing mysql?

2010-03-19 Thread Mattias Thorslund

Robert P. J. Day wrote:

  (just a warning -- as a relative newbie to PHP, i'll probably have
the occasional dumb question.  just humour me.)

  i'm looking at some existing PHP code that accesses a mysql 5.0 db,
and it's coded using the mysql-specific calls:  mysql_connect,
mysql_select_db, etc, etc.

  is there any reason i *wouldn't* want to rewrite that code using the
more general PEAR DB module, and use mysqli?  certainly, as i read it,
using the PEAR DB module would make it easier down the road if i
suddenly decide to change the DB backend.

  anyway, any compelling arguments for or against?

rday
--
  


Well, the reason you shouldn't use PEAR DB in a new project is that it's 
being deprecated. MDB2 is the PEAR successor, and does provide emulation 
for some features that don't exist on all database platforms, such as 
LastInsertID. It can also help you convert your database from one 
platform to another, since it also provides methods for detecting and 
managing the database structure itself (the Manager and Reverse modules).


That said, if I were to start a new project at this time, I would look 
closer at whether PDO fits my needs.


Cheers,

Mattias

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



Re: [PHP] Spreadsheet_Excel_Reader problem

2010-03-18 Thread Mattias Thorslund

Paul M Foster wrote:

I process a lot of CSV files, and what I typically see is that Excel
will enclose fields which might contain commas in quotes. This gets
messy. So I finally wrote a C utility which parses the file and yields
tab-delimited records without the quotes.

Paul
  


And fgetcsv() didn't work for you?

http://www.php.net/fgetcsv

Cheers,

Mattias

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



Re: [PHP] POLL: To add the final ? or not...

2010-01-14 Thread Mattias Thorslund

Kim Madsen wrote:

Mattias Thorslund wrote on 09/01/2010 02:26:
A neat thing with pairing every ?php with a ? when mixed in HTML is 
that these are valid XML processing instructions. If your HTML 
satisfies XML well-formedness, your PHP document will also be valid 
XML. Not that I've ever had any need to process my layout templates 
as XML but anyway.
I don't see your argument. PHP generates HTML or XML files. When 
you're aware of the XML tag of course you make sure the XML file 
generated is valid. Why would you ever add PHP code to a HTML file 
(other than for documentation, examples etc.)?


It's not much of an argument, just an observation. And the conclusions 
are disappointing anyway.


Certainly, if your script is designed to create XML, you'll make sure 
that output is valid when executed by PHP. But it is interesting to note 
that your PHP script file itself might qualify as valid XML under 
certain circumstances, in which case you could process it with an XML 
processor. This would let you modify the XML and still keep the PHP part 
of the file intact.


I haven't seen a live example that might benefit from this, but I still 
find it interesting.


The conditions that would need to be met, are that the content outside 
the ? and ? processing instructions must be well-formed XML, and there 
are places where the processing instructions aren't expected in XML.


This is well-formed XML (and valid PHP):

?xml version=1.0?
?php $var = 'dynamic'; ?
root attr=static
   ?php echo $var content from PHP\n; ?
/root
?php //processing instructions can also be located after the XML content ?

This is not well-formed XML (processing instruction within a tag). Note 
however that the output from PHP would be valid XML:


?xml version=1.0?
?php $var = 'dynamic'; ?
root ?php echo attr=\$var\; ?
   ?php echo $var content from PHP\n; ?
/root

Neither is this (processing instruction within an attribute):

?xml version=1.0?
?php $var = 'dynamic'; ?
root attr=?php echo $var; ?
   ?php echo $var content from PHP\n; ?
/root

And neither is this (missing opening tag for the root element):

?xml version=1.0?
?php $var = 'dynamic'; ?
?php echo root attr=\$var\\n; ?
   ?php echo $var content from PHP\n; ?
/root

A simple way to test this would be to use this:
$sxe = new SimpleXMLElement('the_file.php', null, true);
echo $sxe-asXML().\n;

The inability to insert dynamic content into attributes without breaking 
the XML (ideas anyone?) does limit the usefulness of this technique, so 
I guess it will just remain a curiosity.


Cheers,

Mattias

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



Re: [PHP] Formatting Decimals

2010-01-11 Thread Mattias Thorslund

tedd wrote:

At 2:55 PM -0500 1/11/10, Rick Dwyer wrote:

I have been asked to further modify the value to the nearest half cent.

So if the 3rd decimal spot ends in 1 or 2, it gets rounded down to 0
If it ends in 3, 4, 5, 6 it gets rounded to 5.  And if it 7, 8 or 9 
it gets rounded up to full cents.


Can this be done fairly easily?  Not knowing PHP well, I am not aware 
of the logic to configure this accordingly.


Thanks,
--Rick



--Rick:

The above described rounding algorithm introduces more bias than 
simply using PHP's round() function, which always rounds down. IMO, 
modifying rounding is not worth the effort.


The best rounding algorithm is to look at the last digit and do this:

0 -- no rounding needed.
1-4 round down.
6-9 round up.

In the case of 5, then look to the number that precedes it -- if it is 
even, then round up and if it is odd, then round down -- or vise 
versa, it doesn't make any difference as long as you are consistent.


Here are some examples:

122.4  -- round down (122)
122.6 -- round up (123)
122.5 -- round up (123)

123.4  -- round down (123)
123.6 -- round up (124)
123.5 -- round down (123)

There are people who claim that there's no difference, or are at odds 
with this method, but they simply have not investigated the problem 
sufficiently to see the bias that rounding up/down causes. However, 
that difference is very insignificant and can only be seen after tens 
of thousands iterations.  PHP's rounding function is quite sufficient.


Cheers,

tedd



However that's not what Rick is asking for. He needs a function that 
rounds to the half penny with a bias to rounding up (greedy bosses):



Actual Rounded Diff
.011   .010-.001
.012   .010-.002
.013   .015+.002
.014   .015+.001
.015   .015 .000
.016   .015-.001
.017   .020+.003
.018   .020+.002
.019   .020+.001
.020   .020 .000
Bias   +.005

This could easily be implemented by getting the 3rd decimal and using it 
in a switch() statement.


An unbiased system could look like:

Actual Rounded Diff
.011   .010-.001
.012   .010-.002
.013   .015+.002
.014   .015+.001
.015   .015 .000
.016   .015-.001
.017   .020-.002
.018   .020+.002
.019   .020+.001
.020   .020 .000
Bias.000

The only difference is the case where the third decimal is 7.

Cheers,

Mattias

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



Re: [PHP] Formatting Decimals

2010-01-10 Thread Mattias Thorslund

Testing this out a little:

matt...@mumin:~$ php -r 'echo \$.number_format(0.109, 2, ., ,).\n;'
$0.11
matt...@mumin:~$ php -r 'echo $.number_format(0.109, 2, ., ,).\n;'
$0.11
matt...@mumin:~$ php -r 'echo $.number_format(0.109, 2, ., 
,).\n;'

$0.11

I think the $ should be escaped with a backslash when enclosed within 
double quotes, but even the second and third tries return the correct 
result for me. Using PHP 5.2.10.


Cheers,

Mattias

Rick Dwyer wrote:

Hello List.

Probably an easy question, but I am not able to format a number to 
round up from 3 numbers after the decimal to just 2.


My code looks like this:

$newprice = $.number_format($old_price, 2, ., ,);

and this returns $0.109 when I am looking for $0.11.


I tried:

$newprice = $.round(number_format($old_price, 2, ., ,),2);
But no luck.

Any help is appreciated.

Thanks,

 --Rick






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



Re: [PHP] POLL: To add the final ? or not...

2010-01-08 Thread Mattias Thorslund
Hadn't paid much attention to the issue until reading a previous 
discussion on the topic, here on this list. After that, I decided to be 
consistent and leave the closing ? out in all include files.


To my eyes, ? means look there is more content coming, which seems 
kind of silly when there isn't.


A neat thing with pairing every ?php with a ? when mixed in HTML is 
that these are valid XML processing instructions. If your HTML satisfies 
XML well-formedness, your PHP document will also be valid XML. Not that 
I've ever had any need to process my layout templates as XML but anyway.


Cheers,

Mattias

Daevid Vincent wrote:

I'm having a debate with a co-worker about adding the final ? on a PHP
page...

To be honest, I am the lead, and I could pull rank and be done with the
discussion, however I don't like to be that way. I would rather do the
right thing. If my way of thinking is old-school (I've been coding since
PHP/FI), and what he says is the newfangled proper PHP/Zend way, then I'd
rather adopt that, despite how icky it makes me feel to leave an unclosed
?php just dangling and alone, all sad-like. In my mind, nobody gets left
behind! :)

Is there ANY side-effects to leaving the end ? off? Is it any more work
for the compiler? And yes I know computers are hella-fast and all that, but
I come from the gaming industry where squeeking out an extra FPS matters,
and shaving off 0.01s per row of data in a table matters if you have more
than 100 rows. A 1 second wait IS noticeable and a 10 second is even moreso
-- just try to talk for 10 seconds straight without a pause. Or sit there
and stare at a screen for 10 seconds!

If the main argument is that it's to prevent white-space after the code,
then most modern editors that I'm aware of will automatically trim
white-space (or have a setting to do so). Plus this is ONLY a factor when
you're trying to output a header and things like that. In 90% of your code,
you don't deal with that. It's also obvious enough when you have an extra
character/space because PHP pukes on the screen and TELLS you something
about blah blah sent before header output or something to that effect.

What do you guys all do?

I also created a poll here http://www.rapidpoll.net/arc1opy

-Original Message-
From: Co-worker
To: Daevid Vincent

Actually, Zend states that you should omit the final ? on include pages.
There is no harm in the action, and it prevents you from accidentally
adding white space after the tag which will break the code.  


http://framework.zend.com/manual/en/coding-standard.php-file-formatting.htm
l


-Original Message-
From: Daevid Vincent 
To: Co-worker


Please DO include the final ? I noticed on several of your files that you
have purposely omitted it. Yes, I know the files work without them, but it
makes things easier to see the pairings for matching ?php . Plus it keeps
things consistent and I'm not a big fan of special cases as this is,
especially if it's a bad habit to get into since in all other cases it's
required except this one lazy one. If you are concerned about white space
sending in a header or something, well then just make sure there isn't any.
I've had no problems and it makes you a more careful coder.

Thanks,

Daevid.


  



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



[PHP] Resin/Quercus

2010-01-06 Thread Mattias Thorslund

Hi,

I wonder if anyone has experience with running PHP on the Resin server. 
Opinions, good, bad? Gotchas? Similar projects?


http://www.caucho.com/projects/resin/

Thanks,

Mattias

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



Re: [PHP] Server-side encryption to prevent form hacking: new idea?

2009-12-11 Thread Mattias Thorslund

Kelly Jones wrote:

If you have an HTML form select field xyz with possible values
apple, banana, and cucumber, anyone can easily set xyz to an
arbitrary value.

To prevent this, I create a hidden field code[xyz] with value:
base64_encode(mcrypt_ecb(
 MCRYPT_RIJNDAEL_256,$salt,apple,banana,cucumber,MCRYPT_ENCRYPT));

where $salt is stored in a file outside my webroot.

The script receiving the POST data uses:

mcrypt_ecb(MCRYPT_RIJNDAEL_256,$salt,
 base64_decode($_REQUEST[code][xyz]), MCRYPT_DECRYPT);

and confirms xyz is really one of apple, banana, or cucumber.

Obviously, this can be extended to other types of form fields, and the
check value can be a regular expression or even a function call.

Is this a new idea, or have people done this before?
  


If the server-side script knows which values are expected, then there is 
no need to send that to the client (browser) and back. If this is not 
simply hard-coded in your script, you can keep it in a different file, 
in a database, or in the session, depending on your particular 
situation. For most of the fields, the number of acceptable values 
aren't limited to a small set, so it's more practical to check for 
expected length, data type, and escape the data before saving it.


Cheers,

Mattias

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



Re: [PHP] Re: Time zone discrepancy - America/New_York = CDT?

2009-11-01 Thread Mattias Thorslund

The output I get (after adding newlines to the output) is:
America/New_York
EST
EST
EST

PHP 5.2.10. I suspect this comes from the operating system. Maybe update 
your tzdata package if you're on a Linux system.


Cheers,

Mattias

Nathan Lebovic wrote:

Sorry there was a typo in that output. This is what I'm getting:

date_default_timezone_set(America/New_York);
echo date(e); //output America/New_York
echo date(T); //output CST

date_default_timezone_set(EST);
echo date(e); //output EST
echo date(T); //output EST

- Nathan


On Sun, Nov 1, 2009 at 3:48 AM, Nathan Lebovic nlebo...@gmail.com wrote:
  

I'm using PHP 5.2.6; I just updated timezones with PECL timezonedb to make sure 
that wasn't the problem.

These are the results that I'm getting, which I cannot figure out:

date_default_timezone_set(America/New_York);
echo date(e); //output America/New_York
echo date(T); //output CST

date_default_timezone_set(EST);
echo date(e); //output EST
echo date(T); //output CDT

Any ideas?

Thanks,

- Nathan



  



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



[PHP] SimpleXML var_dump() weirdness

2009-10-13 Thread Mattias Thorslund

Hi,

It seems that var_dump() of a SimpleXMLElement does not show an 
attribute of elements that contain text content?


I hope my examples might show what I mean:

$xml = 'root rootattr=root valueinner attr=value//root';
$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple-asXML();

This results in:

object(SimpleXMLElement)#1 (2) {
 [@attributes]=
 array(1) {
   [rootattr]=
   string(10) root value
 }
 [inner]=
 object(SimpleXMLElement)#2 (1) {
   [@attributes]=
   array(1) {
 [attr]=
 string(5) value
   }
 }
}
?xml version=1.0?
root rootattr=root valueinner attr=value//root

...and that's fine, though it would have been nice to also know that the 
root element is called root.


The second example manifests the weirdness:

$xml = 'root rootattr=root valueinner 
attr=valuetext/inner/root';

$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple-asXML();

Outputs:

object(SimpleXMLElement)#1 (2) {
 [@attributes]=
 array(1) {
   [rootattr]=
   string(10) root value
 }
 [inner]=
 string(4) text
}
?xml version=1.0?
root rootattr=root valueinner attr=valuetext/inner/root

Notice that the attribute attr of the element inner is not displayed.

In the third case, I replace the content of the inner element with 
another element:


$xml = 'root rootattr=root valueinner 
attr=valuedeep//inner/root';

$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple-asXML();

Outputs:

object(SimpleXMLElement)#1 (2) {
 [@attributes]=
 array(1) {
   [rootattr]=
   string(10) root value
 }
 [inner]=
 object(SimpleXMLElement)#2 (2) {
   [@attributes]=
   array(1) {
 [attr]=
 string(5) value
   }
   [deep]=
   object(SimpleXMLElement)#3 (0) {
   }
 }
}
?xml version=1.0?
root rootattr=root valueinner attr=valuedeep//inner/root

The invisible attributes are still accessible with xpath(), etc (the 
asXML() dump shows that it is still present, but just not visible. This 
might be a bug? Or am I just not understanding something?


Cheers,

Mattias
PHP 5.2.6

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



Re: [PHP] Extract links from strings

2009-09-21 Thread Mattias Thorslund

Jônatas Zechim wrote:

Hi there, i've the following strings:

$string1 = 'Lorem ipsum dolor http://site.com sit amet';
$string2 = 'Lorem ipsum dolor http://www.site.com/ sit amet';
$string3 = 'Lorem ipsum dolor http://www.site.net sit amet';

How can I extract the URL from these strings?
They can be [http:// + url] or [www. + url].

Zechim


Simple:

function RemoveLorem($string)
{
   return str_replace(array('Lorem ipsum dolor ', ' sit amet'), '', 
$string);

}

$url1 = RemoveLorem($string1);
$url2 = RemoveLorem($string2);
$url3 = RemoveLorem($string3);

Cheers :-)

Mattias

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



Re: [PHP] Validating XML Issue

2009-09-03 Thread Mattias Thorslund
I'd say your XML document is not well formed, but validity depends on 
whether it conforms to the rules expressed in a schema.


Mattias

Alice Wei wrote:
Hi, 

  This seems like a small problem that I have read from http://us.php.net/manual/en/xmlreader.isvalid.php. 
  I have the code snippet here as follows:


?php
$xml = XMLReader::open('hello.xml');

// You must to use it
$xml-setParserProperty(XMLReader::VALIDATE, true);

if ($xml-isValid()) echo true;
else echo NOT;

?

Here is the contents of hello.xml:

 greetinghelloHello/hello

Obviously, this is not a well formed XML file. 

However, whenever I run the PHP code, it returns true, how do I get it to validate it the way it is supposed to be? 

Thanks for your help. 


Alice




_
Search from any Web page with powerful protection. Get the FREE Windows Live 
Toolbar Today!
http://get.live.com/toolbar/overview
  




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



Re: [PHP] APC optimization in CLI

2009-08-09 Thread Mattias Thorslund

Robert Cummings wrote:

Matic Meznar wrote:

Hi,

When running a PHP script from CLI, does APC optimize it before 
execution, or does APC only provide the apc_*() functions when runing 
in CLI mode?


If I recall correctly, none of the accelerators work in CLI mode.



There is a php.ini setting named apc.enable_cli, which would suggest 
otherwise.


I tried enabling it, and it seems my CLI script is a little faster 
actually. Highly unscientific but looks like about 10%.



Cheers,

Mattias


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



Re: [PHP] Script to Compare Database Structures

2009-08-02 Thread Mattias Thorslund

Look into the Reverse module of PEAR MDB2.
http://pear.php.net/manual/en/package.database.mdb2.intro-reverse-module.php

Cheers,

Mattias

Matt Neimeyer wrote:

I know I CAN hack something together but I hate to reinvent the wheel.

I want to be able to compare the structure of two different clients
databases that might be on different servers that are firewalled away
from each other. Given the two structures it will list all the SQL
commands needed to make the database structure the same.

In a perfect world on one side you would pull up a PHP page that does
a generate structure which would create a downloadable file which
you could then upload to the other system which would then give a
listing of the SQL commands needed to make the local structure match
the uploaded structure.

Thanks in advance...

Matt

  



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



[PHP] Best way to deal with $_SERVER['REQUEST_URI'] on IIS?

2009-04-21 Thread Mattias Thorslund

Hi all,

Apparently, $_SERVER['REQUEST_URI'] doesn't get set the same way when 
running PHP on IIS as when running it on Apache. Specifically, it seems 
to contain the script name only, and not the query string part.


I know I can rewrite my code to piece together a $_SERVER['REQUEST_URI'] 
from $_SERVER['SCRIPT_NAME'] and $_SERVER['QUERY_STRING'], but some 
instances of $_SERVER['REQUEST_URI'] are in third party scripts which 
would be a bit of a pain to fix every time they are updated.


It is a known problem since there are several mentions and workarounds 
to be found on the Internet, but I'm wondering which is currently the 
best way to deal with it. I don't personally run PHP with IIS, so I 
haven't encountered this problem before...but now I have a user who 
does. I could potentially have more users who encounter the same thing, 
so the easier the instructions and the less tinkering, the better. Is 
there a php.ini setting, for instance? What have you found that works 
for you?


Thanks,

Mattias



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



Re: [PHP] Best way to deal with $_SERVER['REQUEST_URI'] on IIS?

2009-04-21 Thread Mattias Thorslund

Andrew Ballard wrote:

On Tue, Apr 21, 2009 at 4:04 PM, Mattias Thorslund matt...@thorslund.us wrote:
  

Hi all,

Apparently, $_SERVER['REQUEST_URI'] doesn't get set the same way when
running PHP on IIS as when running it on Apache. Specifically, it seems to
contain the script name only, and not the query string part.

I know I can rewrite my code to piece together a $_SERVER['REQUEST_URI']
from $_SERVER['SCRIPT_NAME'] and $_SERVER['QUERY_STRING'], but some
instances of $_SERVER['REQUEST_URI'] are in third party scripts which would
be a bit of a pain to fix every time they are updated.

It is a known problem since there are several mentions and workarounds to be
found on the Internet, but I'm wondering which is currently the best way
to deal with it. I don't personally run PHP with IIS, so I haven't
encountered this problem before...but now I have a user who does. I could
potentially have more users who encounter the same thing, so the easier the
instructions and the less tinkering, the better. Is there a php.ini setting,
for instance? What have you found that works for you?

Thanks,

Mattias



It works just fine on the servers where I work.

Andrew
  


Thanks Andrew. I just read that there is supposedly a fix for this in 
FastCGI:

http://ruslany.net/2008/08/update-for-iis-70-fastcgi-module/

You might have that update already. If this fix works, then it's 
obviously the best solution to the problem.


Cheers,

Mattias



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



Re: [PHP] Handling (very) large files with PHP

2009-03-11 Thread Mattias Thorslund

דניאל דנון wrote:

And you got a point - I don't know all the queries I'll run yet, but I'll
probably do them with Perl.
  


From what you described, it doesn't sound overly complicated to do in 
PHP either. If you are more familiar with PHP, it will probably take you 
less time to code it that way. Definitely process the file line-by-line, 
or a few lines at the time.



And although PHP can handle files that large, shouldn't I split them anyway
- in case of some error or debugging, its better to do it before then after,
no?
  


You can use chunks of the file to test the process (and speed up the 
development cycle not having to wait as long for the job to finish).


BTW, do invoke the script via the command-line, i.e. PHP-CLI. That way, 
there is no timeout, so that won't bite you.



I've read a bit about working with large databases,
But since I haven't used REGEX too much on MySQL queries, I would like to
know how long do you think it will take me to do a simple regex search
(likes?) on the database? and it will probably appears in most of the
entries...
  


Regex searches on billions of records will be SLW. Ordinary indexes 
won't be able to help you much there, though you can experiment with 
full-text search.  It might be the solution you are looking for.


Otherwise, process your data more as you import/prepare it, and use more 
specific fields, and proper indexes on those fields. How far you can 
take it will depend a bit on the quality and consistency of your data.


Cheers,

Mattias


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



Re: [PHP] Re: Sorting times

2009-02-15 Thread Mattias Thorslund

German Geek wrote:

The easiest would probably to use
http://nz.php.net/manual/en/function.strnatcmp.php . It would happen to sort
it the right way because am is before pm ;-).
  



Nope. Unfortunately 12 am (midnight) comes before 1 am, and 12 pm (noon) 
comes before 1 pm. Since you have to account for that, you solution 
won't be as elegant.


Cheers,

Mattias

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



Re: [PHP] Re: Global Changes With Loop To Allow Nulls In A Table...

2009-01-27 Thread Mattias Thorslund

Jay Moore wrote:

revDAVE wrote:

Hi Folks,

Newbie question

I have a mysql table with 100 fields, currently all do not allow nulls.
Rather than hand typing in phpMyAdmin, I would like a way to loop 
through

all fields and update them to allow nulls


First I would DESCRIBE the table so you get a list of column names and 
attributes.  Then I would go thru each column and CHANGE it so it has 
the same attributes, adding the NULL flag if necessary.


There may be an easier way however.

Jay



I wouldn't bother mixing in PHP in all this.

In the mysql client, do a SHOW CREATE TABLE tableName\G

(The \G will save you from seeing lots of wrapping -'s)

Copy the returned CREATE TABLE statement, paste into your editor. Re-use 
the column definitions to craft the appropriate ALTER TABLE statement. 
Run in your mysql client, after testing on a copy of the table, or 
backup your data first, whichever is appropriate to your situation..


For a PHP solution, PEAR MDB2 (specifically the Manager and Reverse 
modules) could be used, but I would only use it for recurring situations 
where a generic solution is appropriate, not for a one-off operation 
like this seems to be.


Cheers,

Mattias

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



Re: [PHP] About printing functions

2009-01-21 Thread Mattias Thorslund

Thodoris wrote:

Hi gang,
   Lets say that you have a function that prints something to the 
output simply like this:


function print_str() {
   print blah blah blah;
}

I was wondering if there is a way to use this output and store it in a 
var or something without changing the function itself?

And store the blah blah blah somewhere for later use?

I can think of many reasons that someone could use this.



Perhaps you are looking for what the output buffering functions do?

http://us3.php.net/manual/en/book.outcontrol.php

Cheers,

Mattias



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



Re: [PHP] Re: hello - thread on topic or not?

2009-01-08 Thread Mattias Thorslund

I thought this was the PHP list, not the OS vs. OS list?

Is this type of discussion now considered OK here? I recall people 
getting flamed for borderline off-topic posts even, just a few years ago.


Mattias


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



Re: [PHP] Using MDB2 outside the PEAR framework?

2008-12-26 Thread Mattias Thorslund
As far as I recall, having done this, all that is required for a basic 
MDB2 is the PEAR base class and the driver classes for the platforms you 
want to support.



Murray wrote:

Hi All,

I'm wondering if it's possible or practical to implement MDB2 in my web
application, but without requiring a PEAR installation on the destination
server?

Essentially, I'd like to include MDB2 entirely within my web application, so
I can make use of db abstraction even on servers where PEAR isn't and can't
be installed.

Any suggestions?

Many thanks in advance,

M is for Murray

  



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



Re: [PHP] PHP-CLI and the less command (kubuntu)

2008-07-02 Thread Mattias Thorslund

Stut wrote:

On 2 Jul 2008, at 02:58, Mattias Thorslund wrote:

Hi everyone,

I have a CLI application that produces lots of output to the 
terminal, so I like to send the output along to the less command. 
This has always worked very nicely. Moving to the top or bottom of 
the output used to require just hitting the home or end key, and 
the up and down arrows as well as page up and page down worked nicely.


After upgrading to Hardy on Kubuntu, the behavior changed. Now, it 
seems to preempt the navigation and instead print ugly codes for each 
press on a navigational key (one of those mentioned above), such as 
^[OF. When I press enter, the desired scroll is executed. Scrolling 
up and down is one thing, but it's particularly a pain when trying to 
search through the output, as it would no longer look up previous 
search arguments.


I thought at first it's a problem with Konsole, my terminal program, 
or with less itself. But I've now tried in different terminal 
programs, and reading output other than output from PHP, and the ONLY 
time it happens is when I pipe output from PHP to less. I have 
added a small test script that exhibits the problem on my system. It 
may work well the first time, but when repeating the same command a 
second time, the weird behavior starts.


It could very well be some kind of problem with less, but since I 
can only reproduce the problem with output from PHP CLI, I thought 
it's worth asking here.


Did something about PHP CLI output change lately?


This has nothing to do with PHP. The keystrokes are processed by less 
so your problem lies there or more likely with the terminal emulation 
you're using. Please try a more relevant list.


-Stut


I agree the keystrokes are processed by less. This is probably more a 
problem with less. Yes I will ask on other lists as well.


I thought it was irrelevant to PHP until I tried to provoke the same 
behavior by reading large files or other console input. Nope, only PHP 
output does it, so I figured someone here might have encountered this 
behavior too.


Mattias

Maybe you didn't


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



[PHP] PHP-CLI and the less command (kubuntu)

2008-07-01 Thread Mattias Thorslund

Hi everyone,

I have a CLI application that produces lots of output to the terminal, 
so I like to send the output along to the less command. This has 
always worked very nicely. Moving to the top or bottom of the output 
used to require just hitting the home or end key, and the up and 
down arrows as well as page up and page down worked nicely.


After upgrading to Hardy on Kubuntu, the behavior changed. Now, it seems 
to preempt the navigation and instead print ugly codes for each press on 
a navigational key (one of those mentioned above), such as ^[OF. When 
I press enter, the desired scroll is executed. Scrolling up and down 
is one thing, but it's particularly a pain when trying to search through 
the output, as it would no longer look up previous search arguments.


I thought at first it's a problem with Konsole, my terminal program, or 
with less itself. But I've now tried in different terminal programs, 
and reading output other than output from PHP, and the ONLY time it 
happens is when I pipe output from PHP to less. I have added a small 
test script that exhibits the problem on my system. It may work well the 
first time, but when repeating the same command a second time, the 
weird behavior starts.


It could very well be some kind of problem with less, but since I can 
only reproduce the problem with output from PHP CLI, I thought it's 
worth asking here.


Did something about PHP CLI output change lately?

My test script:

?php

$count = 0;
while ($count  100){

   echo This is line number $count\n;
   $count++;
}

?

Execute like so:
$ php test.php | less

First time might work without problem, but subsequent times not.

Thanks for any feedback and observations.

Mattias

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



[PHP] mnoGoSearch and similar

2008-05-21 Thread Mattias Thorslund

Hi,

I'm looking at possibly implementing mnoGoSearch (for indexing and 
search of uploaded documents on the server) into my application, but 
noticed it has been moved into PECL since PHP 5.1. Does this mean 
mnoGoSearch has been deprecated and there is a different/better solution 
that I should consider first?


Thanks,

Mattias

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



Re: [PHP] mnoGoSearch and similar

2008-05-21 Thread Mattias Thorslund

Dmitri wrote:

Mattias Thorslund wrote:


Hi,

I'm looking at possibly implementing mnoGoSearch (for indexing and 
search of uploaded documents on the server) into my application, but 
noticed it has been moved into PECL since PHP 5.1. Does this mean 
mnoGoSearch has been deprecated and there is a different/better 
solution that I should consider first?


Thanks,

Mattias


Mnogosearch i very good for indexing/search I use it and I like it.
you can just build extension from PECL or you can build php module 
provided by mnogosearch website, which is a little bit harder to do.


Thanks for the recommendation, Dmitri.

I was just wondering because of the move to PECL. I can install it on my 
servers but it users who want to install my application might find it 
too complicated. Also, the PHP manual says the PHP mnoGoSearch module is 
not available for Windows, which some of my users run.


Thanks,

Mattias



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



Re: [PHP] What can cause session_destroy to fail?

2007-06-12 Thread Mattias Thorslund
Jim Lucas wrote:
 Mattias Thorslund wrote:
 Hi,

 One of my clients just received a PHP warning that session_destroy()
 failed. Using the default session handler (with tmp files), what are the
 most likely things that can cause session_destroy() to return false?

 Thanks for any suggestions.

 Mattias

 The session was never initiated on that page with session_start() ??

 on this page

 http://us.php.net/manual/en/function.session-destroy.php

 the first couple comments talk about different ways that the
 session_destroy() function call mail fail?  Any sound close?

I read that too, but (as I read it) it talks about what the function
does, and what you must do to to kill the session properly. But I can't
see what might actually cause the function to return false.

Mattias

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



Re: [PHP] What can cause session_destroy to fail?

2007-06-12 Thread Mattias Thorslund
Jim Lucas wrote:
 Mattias Thorslund wrote:
 Jim Lucas wrote:
 Mattias Thorslund wrote:
 Hi,

 One of my clients just received a PHP warning that session_destroy()
 failed. Using the default session handler (with tmp files), what
 are the
 most likely things that can cause session_destroy() to return false?

 Thanks for any suggestions.

 Mattias

 The session was never initiated on that page with session_start() ??

 on this page

 http://us.php.net/manual/en/function.session-destroy.php

 the first couple comments talk about different ways that the
 session_destroy() function call mail fail?  Any sound close?

 I read that too, but (as I read it) it talks about what the function
 does, and what you must do to to kill the session properly. But I can't
 see what might actually cause the function to return false.

 Mattias


 maybe the fact that the session was never started in the first place

 first off, define failed.  Does it give a fatal error, return false,
 etc... ??

Returns false, as I mentioned twice above. Also returns a PHP warning.

I got some more info now. The error message they get is
session_destroy(): Session object destruction failed.

On my test page, with simply a session_destroy() before any
session_start(), the error (warning) message is Trying to destroy
uninitialized session. This happens both on PHP 4.4.4 and 5.2.1.

So, these are different...

Mattias

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



Re: [PHP] What can cause session_destroy to fail? -- thanks!

2007-06-12 Thread Mattias Thorslund
Richard Lynch wrote:
 On Mon, June 11, 2007 8:36 pm, Mattias Thorslund wrote:
   
 One of my clients just received a PHP warning that session_destroy()
 failed. Using the default session handler (with tmp files), what are
 the
 most likely things that can cause session_destroy() to return false?

 Thanks for any suggestions.
 

 Several things spring to mind...

 root user decided to wipe out /tmp

 root user re-defined where /tmp was, for a new hard drive or
 performance or...

 root user mounted something else on /tmp for a moment (or longer)

 hard drive actually failed

 /tmp was full and some automated process nuked oldest /tmp files

 If the same user was surfing with 2 tabs open, and the session was
 locked by the second tab, and the first tab tried to destroy it...  I
 think it is possible that PHP *might* be unwilling to wait too long
 for the session file to be unlocked so it can be unlinked...  This is
 just a theory.  You'd have to read PHP source to find out for sure, or
 conduct controlled tests.
   
Thanks for some informative suggestions, Richard :-)

Cheers, Mattias

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



[PHP] What can cause session_destroy to fail?

2007-06-11 Thread Mattias Thorslund
Hi,

One of my clients just received a PHP warning that session_destroy()
failed. Using the default session handler (with tmp files), what are the
most likely things that can cause session_destroy() to return false?

Thanks for any suggestions.

Mattias

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



Re: [PHP] Re: What does mean?

2007-05-01 Thread Mattias Thorslund
Man-wai Chang wrote:

 Bash uses only 2. PHP uses 3. And I am using this:

 $sql=
   select ...
 from 
 left join ...
   on 
 where .
 ;


Exactly. I never saw the point in complicating my life with heredocs
when both single- and double-quoted strings can contain multiple lines
anyway.

One thing that does bother me a little with multi-line strings of either
variety is that if I want to avoid inserting extra spaces in the string
at the beginning of each line after the first, I have to left-align the
whole thing and cannot indent it with the rest of my code:

if($something){
if($something_else){
   $myID = intval($_GET['rowID']);
   $sql_pretty =
SELECT
field1,
field2
 FROM
mytable
 WHERE
rowID = $myID;
$sql_ugly =
SELECT
field1,
field2
FROM
mytable
WHERE
rowID = $myID;
}
}

Are there perhaps editors that would DISPLAY multi-line quoted strings
indented to the correct level without inserting extra spaces? Some
editors wrap lines to the correct level, which is also much more
readable, so what I'm thinking of is a bit similar to that.

Mattias

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



Re: [PHP] Re: What does mean?

2007-05-01 Thread Mattias Thorslund
Robert Cummings wrote:
 On Tue, 2007-05-01 at 08:36 -0700, Mattias Thorslund wrote:
   
 Man-wai Chang wrote:
 
 Bash uses only 2. PHP uses 3. And I am using this:

 $sql=
   select ...
 from 
 left join ...
   on 
 where .
 ;
   
 Exactly. I never saw the point in complicating my life with heredocs
 when both single- and double-quoted strings can contain multiple lines
 anyway.

 One thing that does bother me a little with multi-line strings of either
 variety is that if I want to avoid inserting extra spaces in the string
 at the beginning of each line after the first, I have to left-align the
 whole thing and cannot indent it with the rest of my code:

 if($something){
 if($something_else){
$myID = intval($_GET['rowID']);
$sql_pretty =
 SELECT
 field1,
 field2
  FROM
 mytable
  WHERE
 rowID = $myID;
 $sql_ugly =
 SELECT
 field1,
 field2
 FROM
 mytable
 WHERE
 rowID = $myID;
 }
 }

 Are there perhaps editors that would DISPLAY multi-line quoted strings
 indented to the correct level without inserting extra spaces? Some
 editors wrap lines to the correct level, which is also much more
 readable, so what I'm thinking of is a bit similar to that.
 

 Then you'd have an editor that presents something other than what is
 actually there. Go see Microsoft, I'm sure they create rubbish like
 that.

 Cheers,
 Rob.
   

something other than what is actually there

Not at all, Rob! Have you seen how many editors dynamically wrap lines
(Quanta on KDE for instance)? Instead of placing the wrapped line right
smach along the left edge, it indents the following lines under the
first line. It is visually clear that there is no extra white space
because the extra indent has a different background color.

Like this (I used +'s to indicate a different background color, telling
you this isn't whitespace in your code):

if($something){
   $variable = This text message goes on and on and ever on and and
+++would run right off the edge of my screen but thankfully my editor
+++is smart enough to wrap the lines in a way that also does not
+++ruin the indentation.\n;
}

Now, I would wish for my editor to also indent multi-line strings in the
same fashion. Essentially, the lines of $sql_ugly in my example above
should be displayed in alignment with the indentation:

if($something){
   if($something_else){
  $myID = intval($_GET['rowID']);
  $sql =
++SELECT
++   field1,
++   field2
++FROM
++   mytable
++WHERE
++   rowID = $myID;
}
}

I doubt Microsoft develops an editor that I could use on my Linux system
for this...

Cheers,

Mattias

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



[PHP] location of the PHP executable

2007-04-11 Thread Mattias Thorslund
Hi,

I have looked in the documentation but can't find it:

My PHP script (which is run from the command prompt - CLI) needs to know
the file system location of the PHP executable. This is because it needs
to run a second PHP script. I know about the which command but it's
not available in all OSes, and that might not be the currently running
executable anyway.

I could prompt the user for this, but that seems kind of silly. Surely,
there must be some way of looking it up automatically?

Thanks,

Mattias

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



Re: [PHP] location of the PHP executable

2007-04-11 Thread Mattias Thorslund
Jim Lucas wrote:
 Mattias Thorslund wrote:
 Hi,

 I have looked in the documentation but can't find it:

 My PHP script (which is run from the command prompt - CLI) needs to know
 the file system location of the PHP executable. This is because it needs
 to run a second PHP script. I know about the which command but it's
 not available in all OSes, and that might not be the currently running
 executable anyway.

 I could prompt the user for this, but that seems kind of silly. Surely,
 there must be some way of looking it up automatically?

 Thanks,

 Mattias


 What OS are you working with

 Assuming you are on a *nix box this should work

 #locate /php | grep /php$

 this should give you locations that have /php as the end of the line


 on windows you could do this

 cd \
 dir /s php*.exe

Thanks Jim (and others) for the suggestions. I think they will be helpful if 
there
isn't a way to do what I'm looking for:

Ideally, I would like to get the location of the PHP executable that is
actually executing the script. I'm thinking there would be some way to
find out while the script is executing. Something like:

?php
$executable_location = get_location_of_current_executable();
//fictitious function
echo $executable_location .\n;
?

Running it from the command line (again fiction):

$ /my-location-of/php myscript.php
/my-location-of/php
$

I was hoping there's a function or $_SERVER property that would contain
this?

Thanks again,

Mattias

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



Re: [PHP] location of the PHP executable

2007-04-11 Thread Mattias Thorslund
Jochem Maas wrote:

  have you tried looking for this info you want?

   

Yup, but the manual seems kind of light on the subject.


  I can't say for sure if it always exists but on the few boxes
  I tried I found and entry in both $_SERVER and $_ENV:
 
  _ = '/usr/bin/php'

   

I found these in $_ENV and $_SERVER, on Linux. I don't have handy access
to a working Windows installation, yet it needs to work on Windows as well.

If it really does exist on Windows, this might be the ticket, otherwise
a partial solution for Linux only.


  but that was only on linux.
  on windows (where my php cli install is a bit borked),
  I didn't find it but I did find PHPRC which points to
  the directory that the php executable lives in.

   

That's at least something. If someone could confirm, that would be great.

I used the following command (at the command-line) to check the contents
of $_SERVER:

php -r 'print_r($_SERVER);'

Obviously, $_ENV can be checked similarly.


  these maybe of some use.

   

Yes very useful, thanks.


  then again what ever it is your trying to do with the php script
  you seem to need to run inside another instance of php could probably
  be run within the context of the calling script - if you run it inside
  a function you can stop any kind of variable scope clashes (assuming there 
  are
  no symbol name clashes [e.g. duplicate functions/classes]):
 
  function runit()
  {
  include 'myscript.php';
  }
 
  it's just a thought.

   

Unfortunately, I think it's not an option in my case. The sub-process I
run this way are way, way too big to include in the main process.  As
long as I was just running it on my own systems, it was easy to
hard-code the location of the PHP executable but now that it's being
distributed, it needs to just work...

Thanks again,

Mattias

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



Re: [PHP] XML Parsing, starting out.

2006-04-29 Thread Mattias Thorslund
[EMAIL PROTECTED] wrote:
 Hello, 1st msg here so im excited what results i will get :)

 Im a novice with php parsing and have been able to help myself quite well 
 with what ive needed with xml_parse_into_struct and then echoing the fixed 
 variable names but now im dealing with an xml document that is 1st quite 
 large and 2nd changing gradually over time with either added data or changed 
 information. (But not in large numbers)

 http://www.camelotherald.com/xml/spells-si.xml

 It is a spell listing for an online mmorpg. It has a spell_list that 
 captures all other tags and a spell_line for each spell line. Within each 
 spell line is a spell which has the detailed info for each spell with in 
 the spell_line

 I could parse this by echoing the fixed variables but due to its size and the 
 changes done over time its just to much work. This is why i come to a stop. 
 Ive read some guides and tried some example code that should help me through 
 this.

 What i hoped to get is an example with the xml i provided so i could work 
 with it to complete the project.

 The example could look something like this:

 Header with the selected spell_line name ie. Calefaction and below that 
 the spell info in some dummy table format. Then the next spell_line which 
 is Path of Earth then with the spell info in some dummy table setup.

 Thanks for reading and i hope someone can show me the light of a real xml 
 parse.
   

The comments on the Manual page
[http://www.php.net/manual/en/ref.xml.php] contain an example class that
parses an XML file into an associative array. I'm using something
similar myself, as it seems to be a pretty straightforward way to get an
easy-to-use structure in PHP 4 without dom_xml, which isn't always
available.

Mattias

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



Re: [PHP] PHP and CakePHP

2006-03-30 Thread Mattias Thorslund
Pham Huu Le Quoc Phuc wrote:
 I use CakePHP
 The folowing code do not execute:
 td align=center
  ?=(!empty($info['Employee']['dob'])) ?
 $datetime-time2str($info['Employee']['dob']) : ?
  /td
   

Are you sure that

 $info['Employee']['dob'] 

isn't actually empty?

To see if that's the case, you could temporarily change your code to:

 td align=center
  ?=(!empty($info['Employee']['dob'])) ?
 $datetime-time2str($info['Employee']['dob']) : it's empty!!?
  /td

HTH, Mattias

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



Re: [PHP] Re: verification of mail success

2006-02-23 Thread Mattias Thorslund
Manuel Lemos wrote:
 Hello,

 on 02/23/2006 09:22 PM [EMAIL PROTECTED] said the following:
   
 This might be too simple or not...

 I'm trying to send emails from my PHP page, and while both mail() and PEAR 
 Mail
 work, I'm having a hard time finding out whether a message was actually sent 
 or
 not.

 With both mail() and PEAR Mail, an email to an invalid domain (syntactically
 valid) name returned success... Running mailq at the command prompt gives 
 me:

 (Host or domain name not found. Name service error for name=activeagenda.org
 type=MX: Host not found, try again)

 Basically, I'd like my PHP script to know of issues like these.
 

 What you want is impossible most of the time. The problem is that
 usually applications are MUA (Mail User Agents) and so do not deliver
 messages. They rather queue them in the MTA (Mail Transfer Agent) queue.
 So you only know whether the message was successfully deliver or not if
 you request some kind of delivery notification.

 Alternatively, if you want to know whether an address is valid, you may
 want to try this e-mail validation class.

 http://www.phpclasses.org/emailvalidation

 You may also want to try this other class that can act partially as an
 MTA. It is a normal mail composing and sending class with a SMTP
 delivery sub-class that has a direct delivery mode. This means that it
 will attempt to send the message directly to the destination SMTP server
 rather than queueing in the local MTA queue.

 It comes with a wrapper function named urgent_mail(). It is compatible
 with the mail function, except that it uses the class direct delivery
 mode to attempt to deliver the message right away. If it fails due to
 some temporary error, it falls back to the mail() function.

 http://www.phpclasses.org/mimemessage
   

First, thanks for quick replies, everyone!

Manuel: I'll look into the mimemessage class.

Yes I'm aware of the mail queue. I guess what I'm after is way to get a
more detailed status message. I notice that in the mail queue, each
message is given a unique ID, which I suspect could be used for my
purpose, i.e. has the message been processed yet, is there a temporary
or permanent delivery problem, etc. I don't see how the PHP function
would be able to get the message ID of the message it just handed over
to the MTA.

I guess one way would be to implement a queue of my own, and use the
direct SMTP approach to deliver messages.

/Mattias

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



Re: [PHP] Templating engines

2005-04-29 Thread Mattias Thorslund

rush wrote:
Mattias Thorslund [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 

(On the subject of templating engines, again.)
I wonder what you folks think of the following:
http://www.massassi.com/php/articles/template_engines/
   

hi!
It is nicely written, but actually, I think completely oposite from you. The
way I see it, the statement that template system purpose is to separate
bussines logic from presentation, is the biggest missconception about
templates :)
 

Nice turn of phrase. It took me a while to see that you didn't misread 
the article. :-P

Not that I think that bussines logic should not be separated from
presentation logic, it is only that I think that it shold be separated in
your php code design, l, not by the template system. And html, and code
should be separated, one is used to model static and visual concepts, and
another to model  dynamic concepts. And they usually get defined by people
with completely different skills and even mindsets.
 

I suppose this depends on the situation.  If the graphic designers are 
allergic to seeing ?=$var;? instead of {$var}, I suppose a 
templating engine like Smarty or TemplateTamer is the way to go.  Or, if 
you wanted to prevent the graphic designer from adding some complicated 
PHP code in the code , say because they don't understand how to 
structure the code. Or, because the templates will be created and 
uploaded by people who shouldn't have access to upload PHP code to the 
server.

As for the article, I know the author describes putting even pretty 
complicated presentation logic in the template. I agree that that's 
probably not such a good idea.  But I don't see where the 
PHP-as-templating engine concept implies that you couldn't also separate 
the business logic from the (dynamic) presentation logic in the php 
code, before calling the template.   The static layout in the PHP 
'template' file is basically HTML only, with placeholders for the 
dynamic data - only that the placeholders are also valid PHP, not 
yet-another language.

Anyway, I do not think there is One Right Way, of looking at templates. I
for one would never be satsfied with fat temlates like they are in Smarty
for example. But on the other hand I understand that there are people that
would never trade their Smarty templates. So as we do not get to exclusive
about how thing must be done, we could get along nicely :)
 

Agreed.  I don't lose sleep over it :-)
/Mattias
--
More views at http://www.thorslund.us


Re: [PHP] Re: Templating engines

2005-04-29 Thread Mattias Thorslund

Skrol 29 wrote:
What templating engines do you use with php and why?
Ive been using smarty (http://smarty.php.net)
Clive.

I just can't work with PHP the usual way.
Mixing business source and interface source is something too bastard 
for me.
Now that I know templates systems I totaly disagree to say that PHP is a
Template Engine. Ok, it has some basic template features, but they are 
too
poor to use it this way seriously.

Who says PHP itself is a template engine?  I think nobody. What are the 
basic template features? 

However, there is a school of thought regarding templates that advocates 
template engines (written in, for instance, PHP) which use PHP as their 
template syntax, so that there is no need to invent new tags or 
placeholders. You could read the article I linked to before, it has 
examples.  Actually, here's the link again:

http://www.massassi.com/php/articles/template_engines/
Best regards,
Mattias

--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Templating engines

2005-04-29 Thread Mattias Thorslund
Richard Lynch wrote:
Who says PHP itself is a template engine?
   

I do.
 

More importantly, Rasmus does.
 

What? My li'l brother does PHP? Or you mean him Lerdorf?
Sorry...
/Mattias

--
More views at http://www.thorslund.us


Re: [PHP] Re: Templating engines

2005-04-29 Thread Mattias Thorslund
Jason Barnett wrote:
Mattias Thorslund wrote:
...

Who says PHP itself is a template engine?  I think nobody. What are 
the basic template features?

Variables / placeholders
Looping construct(s)
Conditionals
A way to apply styles to text / markup

So I suppose I'm just confused over what constitutes a templating 
engine? I was thinking that the class/tool/program/whatever that handles 
the templates would be the template engine.  I'm aware that a 
PHP-as-template-template would use PHP's native syntax for 
variables/loops/conditionals.

Then I wonder what makes skol29 think PHP's basic template features 
are too poor to be used seriously?  I think PHP's basic template 
features are phenomenal.


However, there is a school of thought regarding templates that 
advocates template engines (written in, for instance, PHP) which use 
PHP as their template syntax, so that there is no need to invent new 
tags or placeholders. You could read the article I linked to before, 
it has examples.  Actually, here's the link again:

http://www.massassi.com/php/articles/template_engines/
The point of this article is that PHP is a good template engine ;)

As I saw it, the PHP class described in the article would be the 
template, but that's obviously a misconception on my part.  What's the 
generic term for the template handling class, then?

Cheers,
Mattias
--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Templating engines

2005-04-29 Thread Mattias Thorslund
Rasmus Lerdorf wrote:
Mattias Thorslund wrote:
Who says PHP itself is a template engine?  I think nobody. 

I do.
It comes down to whether you want the delineation between the template 
and the business logic enforced by the system or not.  PHP is a 
general-purpose templating system that does not enforce this 
delineation.  

That explanation is sensible enough.
[skipping ahead a little]
The approach I tend to point people at is something I have been 
calling a Template API.  That is, when you build your application, you 
create a template api to go along with it.  In essence you are 
creating a templating system for each application you write.

For many projects, I think the approach you describe in the example 
(below) is appropriate. One nice thing is that output can begin before 
the whole page has been nearly processed.  I don't know if many other 
templating solutions can do that.

To me, it looks like it would be hard to keep the functions that are 
called by the template to a reasonable format or number, at least in a 
larger project.  If it's a template that is to be used by many kinds of 
pages, there would be either a large number of functions, or there would 
be generic functions that need to do different things based on the 
situation.

Of course, the functions could become methods of a page object. Then, 
it gets easy to create specialized subclasses of page objects which can 
respond differently to the same generic method call.  Sounds more 
attractive the more I think about it :-)

Then again, if I need a big object to handle the business logic (and 
dynamic presentation logic) because my template approach is sequential, 
it might be a toss-up compared to using sequential business logic and a 
small template object.


For example, I describe a simple such system here:
   http://talks.php.net/show/mtladv05/20
To me, this is a perfectly good template (from the slide):
  ?php
  start_poll(1);
  $os = array(FreeBSD,Linux,OSX,Windows,Other);
  ?
  p class=purpose
  Please answer a couple of questions for us.
  /p
  p class=question
  1. What is your name?
  /p
  ?php text_answer('name',64)?
  p class=question
  2. Which operating systems do you use on a daily basis?
  /p
  ?php select_any_of($os)?
  p class=question
  3. Which operating system do you prefer?
  /p
  ?php select_one_of($os)?
  ?php end_poll(); ?
The end_poll() call could be eliminated as well to make it slightly 
cleaner, but otherwise this is straight-forward with no mixing of 
business-logic and content.

My main issue with general-purpose templating systems is that they 
always end up inventing a new language.  

Except the class described in the article I was talking about.  It uses 
PHP as the template language.  It's a big reason why I find it attractive.

[skipping discussion on Smarty]
As far as I am concerned you shouldn't be dealing with any sort of 
objects from a template to begin with. 

This does place some demands on the business logic. 

There should be nothing but simple variables and straight function 
calls from a template, but this is a religious issue that people will 
never agree on.  Hence PHP's neutral approach where the exact 
templating delienation is left up to the users.

No doubt, people will continue to argue over it for a long time to 
come.  I try not to be religious about it, I simply want to know as many 
sides of the issue as possible.

Best,
Mattias
--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Templating engines

2005-04-28 Thread Mattias Thorslund
(On the subject of templating engines, again.)
I wonder what you folks think of the following:
http://www.massassi.com/php/articles/template_engines/
I've been using the template class in the example of the article. I 
think it's easy to use and very flexible, since it uses PHP as the 
actual template language. I haven't used in a production setting yet, 
and haven't compared its performance with other template systems.

/Mattias
P.S. Sorry for hijacking this thread, but it's closely related.  OK, I 
wrote that before I read all the off-topic jokes in this thread. I don't 
feel sorry anymore :-)

--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[suspicious - maybe spam] [PHP] [suspicious - maybe spam] Re: [PHP] Unexpected T_IF

2005-04-25 Thread Mattias Thorslund

ztuni ztuni wrote:
I'm experiencing an unexpected T_IF error, and after digging through
miles of code, came up empty. The relevant code, along with the if
statement
Parse error: parse error, unexpected T_IF in
/var/www/html/phpBB2/posting.php on line 562
if ( !($result = $db-sql_query($sql)) )
 

(snipped the rest of the code)
Check that the line BEFORE the if statement ends with a semicolon (or 
otherwise ends correctly...).

/Mattias
--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Date class

2005-04-19 Thread Mattias Thorslund
Devraj Mukherjee wrote:
Everyone,
Do you know of any decent Date/Time handling classes? We require the 
following functionality

1. Date's prior to 1970 handled (not reliant on the PHP date)
2. add/subtract days to/from a date
3. subtract two dates returning number of days
Any pointers are welcome. Thanks for your time in advance.
Devraj

Have you looked at the PEAR Date class?
http://pear.php.net/package/Date
/Mattias
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Links exchange with http://php-faq.com. OT - SPAM

2005-04-19 Thread Mattias Thorslund
Ann Clark wrote:
Hello,
 We would like to exchange links between your site http://php-faq.com and 
our new exciting casino web site.
Our site do NOT offer online gambling, it have information about different 
aspects of gambling and so it's very good and informative from our point of 
view.
We require that our link to you is reciprocated. So please add our link to your 
site and send us it location, we will reply within 72 hours.
Information about our site is next:
 

[snipped link]
Link Title: Online Casinos
Description: All Best Online Casino Games are here!

Best regards, Ann Clark.
 

It would be nice if the above piece of blatant spam were removed from 
the archives, since the spammer's objective most likely is to improve 
their Google rank...

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


[suspicious - maybe spam] [PHP] [suspicious - maybe spam] Re: [PHP] How do I get the first element's key of an array of objects?

2005-04-08 Thread Mattias Thorslund

Chris W. Parker wrote:
Read www.php.net/array_keys and you shall have your answer.
From the php docs:
?php
 $array = array(0 = 100, color = red);
 print_r(array_keys($array));
?
Will output.
Array
(
   [0] = 0
   [1] = color
)
 

Duh!  Yes, I replied a little too fast on that one.
/Mattias

--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[suspicious - maybe spam] [PHP] [suspicious - maybe spam] Re: [PHP] How do I get the first element's key of an array of objects?

2005-04-07 Thread Mattias Thorslund

Chris W. Parker wrote:
While looking through the array functions I saw www.php.net/array_keys
and thought of:
?php
   $keys = array_keys($object_array);
   $first_key = $keys[0];
?
 

I wonder if that will work, when the first element has the key 3... ?
This might work better:
$keys = array_keys($object_array);
$first_key = reset($keys);
/Mattias

--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[suspicious - maybe spam] [PHP] [suspicious - maybe spam] Re: [PHP] Interesting, yet goofy behavior

2005-04-06 Thread Mattias Thorslund
But, Jay:
Am I missing something here?  It's obvious that the 'bid' parameter will 
appear in the query string... That's how the form posts it.

Yes, you can unset it if you like, but the form will still add it to the 
URL that it posts to, unless you change the action attribute of the 
form tag.

Actually I wonder how much alcohol you've had by now... :-)
/Mattias
Jay Blanchard wrote:
Let's say I have a form and the action is thus;
form name=\managebatch\ action=\ . basename($PHP_SELF) .
?bid=edit\ method=\POST\\n;
Note the 'bid' attribute. Now, I have a case statement in which stuff
takes place since the form has called it because of the 'bid' attribute.
Before I break from the case I do this;
unset($_GET['bid']);
SIDEBAR: You should all note that I ma editing someone else's code.
Someone who did not bother to comment their code. [ed note: Yes, they
work for the same company, but are not in the department, yet management
says that I have to support their code. I asked if we could at least
teach them commenting and revision control. They looked at me as if I
was a space alien]. Someone who believes that all forms should use
$PHP_SELF (because whatever book they have showed them this, so
therefore it must be good for everything).
The URL comes back and the 'bid' attribute is still there. Is this to be
expected? If so, do you have any advice (other than copious amounts of
alcohol) for dealing with this? 

Thank you, I really appreciate your help.
 

--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Interesting, yet goofy behavior

2005-04-06 Thread Mattias Thorslund
Jay Blanchard wrote:
[snip]
Am I missing something here?  It's obvious that the 'bid' parameter will
appear in the query string... That's how the form posts it.
Yes, you can unset it if you like, but the form will still add it to the
URL that it posts to, unless you change the action attribute of the 
form tag.

Actually I wonder how much alcohol you've had by now... :-)
[/snip]
You may be right, I may have been looking at this for too long. And I
see that yu are right about the query string too, of course. Not enough
sleep and/or food on my part. I will have to find another way around the
situation then. Thanks!
 

How about:
form name=\managebatch\ action=\ . basename($PHP_SELF) .
?bid= . $_GET['bid'] . \ method=\POST\
If your Form tag appears after your switch/case statement, that is?
But, first, do yourself and your project a favor and go grab something 
to eat.  :-)

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


Re: [PHP] SQL ternary thing

2005-04-06 Thread Mattias Thorslund
Rory Browne wrote:
Hi
I appreciate this is an SQL issue, more than a PHP issue, but since it
isn't a DB specific issue, and I'm planning on using it with PHP(and
I'm not subscribed to any SQL lists), I thought I'd post it here.
I have a table a bit like the following:
create table thing (name char(10), value boolean, name_if_true
char(10), name_if_false(10))
Basicly what will be modified will be the value field. name_if_true,
and name_if_false are static(and will in practice be in a different
table). The table may look a bit like the following:
| Accept | 0 | Yes | No |
| Gender | 1 | Female | Male
| State | 0 | Broken |fixed 

Can anyone suggest a query that will return:
| Accept | No
| Gender | Female
| State | fixed
Preferably in a db independent manner.
 

Look into the CASE statement.  You can use it in the SELECT part of your 
query. MySQL also has an IF statement, but I believe that's not 
supported by other DBMS's.

Something like:
SELECT
name,
CASE value
  WHEN 1 THEN name_if_true
  WHEN 0 THEN name_if_false
  ELSE 'unknown' END AS result
FROM thing;
/Mattias
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[suspicious - maybe spam] [PHP] [suspicious - maybe spam] Re: [PHP] Include file

2005-03-30 Thread Mattias Thorslund

Jay Blanchard wrote:
I try to use both types of quotes in the proper circumstance. Having
said that, I came to computing in the age where we worried over CPU
cycles, but I don't see how in this day and age the difference between
the two would even matter. Even on a high load site the difference
between the two would be negligible.
 

This has been talked about on this list so many times.
Another way to put it would be:
...because in most real-world scripts, the execution time for this kind 
of operation (the string parsing) is negligible compared to the script's 
total execution time. So even if you could reduce the time it took to 
parse strings to nothing, you wouldn't speed up the total execution time 
very much.

If you want to optimize the performance of your scripts, there are 
probably a lot of other things that should be much higher on your 
priority list than substituting double quotes with single quotes.

/Mattias Thorslund
--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[suspicious - maybe spam] [PHP] [suspicious - maybe spam] Re: [PHP] 'Insulate' db connection

2005-03-06 Thread Mattias Thorslund
Since you can use fopen, I don't think open_basedir is the problem. 
Read about open_basedir here: http://us3.php.net/features.safe-mode

Maybe the path that you use in the include is wrong?
/Mattias
Andre Dubuc wrote:
Hi,
I am trying to 'insulate' my database connection from prying eyes by moving 
the db connection code to a directory above docroot and then calling it by an 
include. However, my IP has an open_basedir restriction in effect that 
defeats what I'm trying to do.

Perhaps I'm unclear what what the open_basedir does, and perhaps IP is 
protecting me from an even worse security risk. However, I can call, using 
fopen, many counter code pages that reside in the directory above docroot - 
so I'm confused here. Perhaps it's the use of include - is there another way 
to do this? 

***
The code so far:
On any page that needs a db connection (in docroot path):
?php

include(db-conn.php);
...
?
Db code page (located in directory above docroot):
?php
$db = pg_connect(dbname=site user=confused password=toughone);
?
Tia,
Andre
 

--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[suspicious - maybe spam] [PHP] [suspicious - maybe spam] Re: [PHP] Re: Help with dates

2005-03-06 Thread Mattias Thorslund
M. Sokolewicz wrote:
well, you can simply use the unix timestamp, since the amount of days 
/ seconds since 0 AD/BC will be a constant (it won't change, trust 
me), you can simply add it to that, and add a wrapper function to 
php's time(). You'll be working with VERY big numbers in that case, so 
you can also do it the other way around; store the amount of DAYS 
since 0 AD/BC till Jan 1st 1970, add time()/86400, and you'll have the 
amount of days since 0 AD/BC in an integer (or float, depending on how 
many days that really are).

You'll just need to find that constant somewhere :)
Can't be too hard to calculate it:
1970 * 365 + 1 day for each leap year. Note the rules for leap year, of 
course.

/Mattias
--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[suspicious - maybe spam] [PHP] [suspicious - maybe spam] Re: Help with dates

2005-03-06 Thread Mattias Thorslund
Check out:
http://pear.php.net/package/Date
According to the description, it lets you compare dates that date pre 
1970 and post 2038.

/Mattias
(If I could only get off ezmlm's suspicious user list. I think there 
isn't much I can do, it's my ISP rejecting some PHP list postings.)

Kevin wrote:
Greetings Mr Mattias,
I wish it was so simple. Because the dates that may need calculating can be
before 1970.
THis function I have.. and it's semi-working, but I've noticed
irregularities during the conversion.
Thanks for your suggestion!!
Yours,
Kevin
Mattias Thorslund [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 

M. Sokolewicz wrote:
   

well, you can simply use the unix timestamp, since the amount of days
/ seconds since 0 AD/BC will be a constant (it won't change, trust
me), you can simply add it to that, and add a wrapper function to
php's time(). You'll be working with VERY big numbers in that case, so
you can also do it the other way around; store the amount of DAYS
since 0 AD/BC till Jan 1st 1970, add time()/86400, and you'll have the
amount of days since 0 AD/BC in an integer (or float, depending on how
many days that really are).
You'll just need to find that constant somewhere :)
 

Can't be too hard to calculate it:
1970 * 365 + 1 day for each leap year. Note the rules for leap year, of
course.
/Mattias
--
More views at http://www.thorslund.us
   

 

--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] sentence case

2005-02-23 Thread Mattias Thorslund
Chris W. Parker wrote:
Leif Gregory mailto:[EMAIL PROTECTED]
   on Wednesday, February 23, 2005 10:31 AM said:
 

I'm thinking something like:
1. strtolower() the string
2. explode() on the period
3. Loop through the resulting array
  a. trim() whitespace on each element
  b. ucfirst() on each element of the array
  c. Concatenate the string back together, putting a period and a
 space at the end of each element.
   

And on top of that he'll need to convert all 'i' to 'I' because of step
1.
 

... and to be really picky, convert common acronyms to upper-case as 
well. :-)

That chould be done with str_replace and arrays for 'find' and 'replace' 
- the challenge is to come up with the list of acronyms...

$find = array('stfu', 'rtfm', 'lol');
$replace = array('STFU', 'RTFM', 'LOL');
$replaced_string = str_replace($find, $replace, $old_string);
Of course, se notice that the content of $replace is the same as $find, 
but upper-cased. Is there a more elegant solution?

/Mattas
--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] sentence case

2005-02-23 Thread Mattias Thorslund
Leif Gregory wrote:
Hello Chris,
Wednesday, February 23, 2005, 11:49:32 AM, you wrote:
C And on top of that he'll need to convert all 'i' to 'I' because of
C step 1.
You and Mattias both have valid points.
The only other thing I can think of is a regexp that is searching for
a period and a space then does a ucwords() on the following word, but
that's a lot of work to pull things apart like that! grin
 

Could be done, still.
Oh, and sentences may end with other characters, too. Notably ! and ?.
--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Help with a query please - unable to error check!

2005-02-16 Thread Mattias Thorslund
Could it be a quote-escaping problem?
It would be easier to tell if you could show us the query and the code 
you're using.

/Mattias
Shaun wrote:
Hi,
I have a problem with a query, I get the following error message:
You have an error in your SQL syntax. Check the manual that corresponds to 
your MySQL server version for the right syntax to use near '' at line 23

If I echo the query to the screen and run the query to the database via SSH 
it executes correctly.

Does anyone have any ideas on what else I can check for here?
Thanks. 

 

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


Re: [PHP] Primer for working with arrays

2005-02-09 Thread Mattias Thorslund
Robert Sossomon wrote:
I need a really good primer for working with arrays in PHP and with 
MySQL.  I can do what I need to do without them right now, but I would 
really like to get arrays figured out.
The PHP Cookbook (O'Reilly book) has this, both in the Arrays and 
Databases chapters.

/Mattias
--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] strange in MySQL Query.

2005-01-15 Thread Mattias Thorslund

... I dont know why .. is this mysql bug ?
It's a known bug in MySQL.  Since this is a PHP list, I leave it up to 
you to check what version fixed it.
IIRC, it's possible to work around by making sure the first statement 
has the longest data type.

--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Form Validation

2004-10-13 Thread Mattias Thorslund
There are several JavaScript solutions for validating forms on the 
client side. Search on hotscripts.com and google.com.

Client-side validation (in the browser) is useful, but you shouldn't 
depend on it to guarantee that the data that your users submit is 
valid.  You should also validate the data in your PHP script as you 
process the form.

Oh, and there are several PHP-based list managers available, for 
instance phplist, so you may not need to program it yourself.

/Mattias
Huang, Ou wrote:
I am currently working on a newsletter mailing list project and
developed a form in php. I would like to validate before it is
submitted. What would be the best way to validate a form? Write your own
routines or using a form validator. I just started learning PHP, so
don't have much experience on this. I am thinking using a form validator
but not sure where I can get it. 

Any suggestions would be appreciated! 

Thanks.
 


--
More views at http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Recommendations for php email list managers?

2004-09-21 Thread Mattias Thorslund
Hi,
I'm trying to set up a list manager on a hosted site.  PHPlist 
(phplist.com) seemed promising but I read on their forums that it takes 
some users hours and hours to send a couple thousand emails.  Without 
terminal access, I suspect the PHP sending page will time out long 
before most of my emails have been sent.

Does anyone have suggestions for a quicker mailer?  I'd like to be able 
to import users in bulk, and I'd like to let users sign up and 
unsubscribe automatically.  PHPlist does all that but... I don't want to 
set it all up and then find out I can't send my newsletter.  It's 
supposed to be an announcement-only list, BTW.

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


Re: [PHP] Re: Recommendations for php email list managers?

2004-09-21 Thread Mattias Thorslund
Manuel Lemos wrote:
Hello,
On 09/21/2004 04:17 PM, Mattias Thorslund wrote:
I'm trying to set up a list manager on a hosted site.  PHPlist 
(phplist.com) seemed promising but I read on their forums that it 
takes some users hours and hours to send a couple thousand emails.  
Without terminal access, I suspect the PHP sending page will time out 
long before most of my emails have been sent.

Does anyone have suggestions for a quicker mailer?  I'd like to be 
able to import users in bulk, and I'd like to let users sign up and 
unsubscribe automatically.  PHPlist does all that but... I don't want 
to set it all up and then find out I can't send my newsletter.  It's 
supposed to be an announcement-only list, BTW.

Depending on your host operating system and local mailer, there are 
ways to tell to just queue the messages and deliver them later when 
possible, freeing your PHP much faster to queue messages to different 
recipients. Just let me know which OS and local mailer system 
(sendmail, qmail, postfix, exim, IIS, Exchange, etc.) do you use so I 
can advise.

I'm aftaid I have very limited information about the server 
configuration. I'll have to ask my host since I can't find the info on 
their web site. 

Thanks for your reply.
/Mattias
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Recommendations for php email list managers?

2004-09-21 Thread Mattias Thorslund
Matthew Weier O'Phinney wrote:
* Mattias Thorslund [EMAIL PROTECTED]:
 

I'm trying to set up a list manager on a hosted site.  PHPlist 
(phplist.com) seemed promising but I read on their forums that it takes 
some users hours and hours to send a couple thousand emails.  Without 
terminal access, I suspect the PHP sending page will time out long 
before most of my emails have been sent.
   

You're comparing apples to oranges here. The amount of time it takes to
send the mails isn't based on PHPList but on:
1) The MTA being used to send the mails and
  1a) how that MTA is configured
2) Available bandwidth
 

[snip]
So, you can see, the mailer is less dependent on the frontend (PHPlist,
to use your example) than on the underlying server architecture.
 

Thanks for explaining. I'll have to ask my hosting provider about the 
details.

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


Re: [PHP] RE: **[SPAM]** [PHP] Correct context

2004-09-20 Thread Mattias Thorslund
Jay Blanchard wrote:
[snip]
Before I go screwing this code up I thought I would ask for the
formatting. How would you write the following in PHP?
if $entry not equal to Copy Change
OR
Banner Change
OR
Price Change
AND
$row['photo_check'] not equal to 
[/snip]
There are several ways  here is one
if(( != $row['photo_check'])  ((Copy Change != $entry) || (Banner
Change != $entry) || (Price Change != $entry)))
Note the parentheses to define preference order.
 

How about :
if( != $row['photo_check'])){
	switch($entry){
	case Copy Change: 
	case Banner Change:
	case Price Change:
		break;
	default:
		//put your code here
	}
}

Longer but seems more readable to me.
Disclaimer: I have probably left a silly typo somewhere.
/Mattias
--
http://www.thorslund.us
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] RE: **[SPAM]** [PHP] Correct context

2004-09-20 Thread Mattias Thorslund
Mattias Thorslund wrote:
Disclaimer: I have probably left a silly typo somewhere. 

Sure did:
My old nemesis, end parethesis (either too few or too many).
It should be:
if( != $row['photo_check']){
   switch($entry){
   case Copy Change:
   case Banner Change:
   case Price Change:
   break;
   default:
   //put your code here
   }
}

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


Re: [PHP] RE: Correct context

2004-09-20 Thread Mattias Thorslund
Jay Blanchard wrote:
Oops
 

Yeah, some of us (including myself) could use a php validator in our 
mail clients...  Maybe a plugin for T-bird?

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


Re: [PHP] downloading files

2004-08-19 Thread Mattias Thorslund
Aaron Todd wrote:
I posted a simular question before and never really got an answer.  The post
drifted off into some other valuable information, but I still have the same
question.
I am trying to create a site with file downloads.  The files on the server
that are to be downloaded need to be protected somehow.  I have already
created a login page for the site so users must log in.  The download files
are in a directory protected by htaccess which it is my understanding that
PHP can go underneath htaccess to get access to the files.  My problem is
where do I put this directory?  I was already told to put it outside the web
root directory, but I really dont know where the best place is.
Anyone have a suggestion?
Thanks,
Aaron
 

I use the following structure (simplified):
/path/to/web/sites
  /website1
 /classes   (php classes)
 /templates (page templates, as with Smarty)
 /documents (put uploaded documents here)
 /webroot   (web-accessible files here)
/img(static images)
/js (javascript files)
Hope this helps.
Mattias
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] SQL Join query

2004-08-09 Thread Mattias Thorslund
(Sorry about all the quoting but I thought it makes sense for clarity - 
Mattias)

Curt Zirzow wrote:
* Thus wrote Lenar Lhmus:
 

Mattias Thorslund wrote:
   

Though, (regardless of SQL database platform) in a case like this, it
MAY be both more straightforward and efficient to use two separate
queries for the pictures and comments, given the one-to-many cardinality
between them.  The above statement causes redundant data to be returned
- it duplicates the pics record for each new comment.  If there are many
large columns in the pics table and many comments to each record there's
a lot of redundant data in a query like that.
 

No, I think you are wrong. There was GROUP BY pics.id so it won't return
duplicate data. And probable overhead is eliminated too I think - DBserver
will optimize and will join data from pic_comments only once for each
unique pics.id.
   

The results will be something like:
id submitter count pic_id comment
1  joe4  1comment1
1  joe4  1comment2
1  joe4  1comment3
1  joe4  1comment4
2  john   0  2NULL
3  jim5  3comment6
3  jim5  3comment7
3  jim5  3comment8
3  jim5  3comment9
3  jim5  3comment10
Exactly. 

To make it REALLY obvious, I'll point out what parts of the data set 
that are redundant by replacing them with stars, using Curt's example above:

id  submitter   count pic_id  comment
1   joe 4 1   comment1
*   *   * *   comment2
*   *   * *   comment3
*   *   * *   comment4
2   john0 2   NULL
3   jim 5 3   comment6
*   *   * *   comment7
*   *   * *   comment8
*   *   * *   comment9
*   *   * *   comment10
The actual table structure from the original poster (an ex-namesake of 
mine*) would result in seven columns with redundant data, i.e. where 
data is needlessly repeated for every picture that has two or more 
comments..  It wouldn't be hard to find worse real-world examples.

pics table:
| id | submitter | time | date | category |
pic_comments table:
| pic_id | comment |
- Mattias Thorslund
(*) My last name used to be Jönsson, too.  Americans just can't 
pronounce it right.

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


Re: [PHP] SQL Join query

2004-08-07 Thread Mattias Thorslund
Lenar Lõhmus wrote:
Anyway, instead of writing this:
SELECT pics.*, pic_comments.*, count(*) AS num_comments FROM pics, 
pic_comments WHERE pics.category = 1 AND pics.id = pic_comments.pic_id 
GROUP BY pic_comments.pic_id;

Write this:
SELECT pics.*, pic_comments.*, count(*) AS num_comments FROM pics
LEFT JOIN pic_comments ON (pic_comments.pic_id = pics.id)
WHERE pics.category = 1
GROUP BY pics.pic_id;
Lenar

Though, (regardless of SQL database platform) in a case like this, it 
MAY be both more straightforward and efficient to use two separate 
queries for the pictures and comments, given the one-to-many cardinality 
between them.  The above statement causes redundant data to be returned 
- it duplicates the pics record for each new comment.  If there are many 
large columns in the pics table and many comments to each record there's 
a lot of redundant data in a query like that.

Depending on the nature of your data, this may or may not outweigh the 
added cost of one more query to the database.  The choice will obviously 
affect the way you have to write your PHP code (hey, now I'm on-topic).
Splitting it up, it could look like this:

SELECT *
FROM pics;
SELECT *, count(*) AS num_comments
FROM pic_comments
GROUP BY pic_id
You may want to add an ORDER BY clause to both of these. People often 
say it's 'good form' to enumerate your fields in the SELECT clause but 
benefits of that may vary between database platforms.

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


Re: [PHP] Hierarchies and MySQL with PHP

2004-06-28 Thread Mattias Thorslund
Warren Vail wrote:
I did one once where the key to the table was a string, and the string
contained 1 to n Node Numbers separated by a separator character.
1
1.1
1.1.1
1.2
select data from table where node between (1 and 2)
resulted in an entire limb of the tree being retrieved.  Limitations were
the size of the string, depth of the tree (the string was truncated), and
the number of digits in each node number.  Problem also with ordering node
numbers, node number 1 tended to be followed by node number 10, 11, 12, etc,
then number 2, until I pre-determined the number of leading zeros for each
node.
Not pretty, but it works well for small trees.
Warren Vail
 

Been there, done that, ran into the same limitations :-)
The flat table solution in the article suggested by Marek keeps a 
running display order integer column, updated only when items are 
added (or removed, but that's not strictly necessary if you don't mind 
holes in the sequence).  When inserting a new item, it gets the display 
order value of the parent + 1, and the following items have their 
display order incremented by 1. Simple.  There's also an indentation 
level column, which is simple enough to maintain.

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


[PHP] Hierarchies and MySQL with PHP

2004-06-27 Thread Mattias Thorslund
Hi,
I wonder what you think are the best (or least worst) strategies to 
store and retrieve hierarchial data (such as a threaded discussion or 
a multi-level menu tree) in MySQL using PHP?

I have been using table structures where each row contains a parent 
reference, such as:

Table Example:
Field namedata type/db flagsComents
=
RowID int unsigned auto_increment not null  (primary key)
ParentRowID   int unsigned  0 (or NULL if at top 
level)
Name  varchar(50)

... which is OK for *defining* the hierarchy.  However, it's a pain to 
retrieve the data so that it can be displayed in a nice threaded/sorted 
way, where children are sorted directly below their parents.  I also 
want the items to be nicely sorted within their own branch, of course.

On MS SQL, I successfully used stored procedures that employ temporary 
tables and while statements and the like.  That method is not available 
in MySQL (yet), so I'll have to do a lot of the manipulation on the web 
server instead, using PHP.

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


Re: [PHP] Hierarchies and MySQL with PHP

2004-06-27 Thread Mattias Thorslund
Marek Kilimajer wrote:
This should be of your interest:
http://www.evolt.org/article/Four_ways_to_work_with_hierarchical_data/17/4047/ 


Indeed!  The flat table model is simple, efficient and - I think - 
sufficient. Thanks!

I also found this article which explains the fourth method not really 
described above, despite the title:
http://www.sitepoint.com/article/hierarchical-data-database/

That method is a bit more complicated but it also allows you to 
determine the (total) number of child nodes of a node, without an extra 
SQL query.

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


[PHP] include_once changed behavior?

2004-06-07 Thread Mattias Thorslund
Hi,
In order to keep configuration files outside the web root I use:
include_once('../config.php');
This used to work also when running php scripts from the command line. 
Now I have a new server and I get no such file or directory when using 
this construct from the command line.

I have worked around this by doing this:
$main_folder = realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/..');
include_once($main_folder . '/config.php');
The original, simpler construct still works when calling the page from a 
web browser, just not when I run it from the command line. 

The new server has a more recent version of PHP (4.3.4). I don't have 
the php version of the old server but it was on RedHat 9 - now I'm on 
Mandrake 10.

What could be the difference that caused this? 

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


Re: [PHP] include_once changed behavior?

2004-06-07 Thread Mattias Thorslund

Jason Wong wrote:
On Tuesday 08 June 2004 03:21, Mattias Thorslund wrote:
 

In order to keep configuration files outside the web root I use:
include_once('../config.php');
This used to work also when running php scripts from the command line.
Now I have a new server and I get no such file or directory when using
this construct from the command line.
I have worked around this by doing this:
$main_folder = realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/..');
include_once($main_folder . '/config.php');
The original, simpler construct still works when calling the page from a
web browser, just not when I run it from the command line.
The new server has a more recent version of PHP (4.3.4). I don't have
the php version of the old server but it was on RedHat 9 - now I'm on
Mandrake 10.
What could be the difference that caused this?
   

Possibly:
 manual  Using PHP from the command line  -c switch
 

...except I don't  use the -c switch? 

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


Re: [PHP] Update problem

2004-06-07 Thread Mattias Thorslund
That will work, but the below is really supposed to work.  I use it in 
my apps.

Blake Schroeder wrote:
Put a hidden field in your form named id.
-Blake
Mattias Thorslund wrote:
Probably with
form method=post action=foo.php?id=123

Blake Schroeder wrote:
The form that is being submitted can only be a POST or a GET not both
example:
form method=post action=foo.php
input type=text name=foo1
input type=submit
/form
How can you do both?
-Blake
Maldiv wrote:
Hello,
I have a php update form which use $_POST and $_GET too. I call the 
update
like this update.php?id=1
And after the user submit the form with new data I use command like 
this:
UPDATE table SET id=$_POST['id'] WHERE $_GET['id']='1';

This code works on localhost with Apache 2, Win XP, and Php 4.3.5 
but it
doesn't works on my real server(Php 4.3.3, Linux, Apache 1.??)
I debuged it and I realised that on localhost I have the correct 
value in
the $_GET but in remote $_GET is empty.

What can I do?
Thanks!
 







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


Re: [PHP] include_once changed behavior?

2004-06-07 Thread Mattias Thorslund
Marek Kilimajer wrote:
cli php uses path relative to your current directory, cgi php uses 
path relative to the executing script.
That IS interesting.  That would explain why:
php /var/www/myproject/util/my-cli-script.php
... will break unless I execute it from that same directory.
I used to be able to do that from anywhere, though - that's why I passed 
the full path to the script.  So it's got to be some configuration 
that's different, or that this behavior has changed.

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


Re: [PHP] Update problem

2004-06-07 Thread Mattias Thorslund
To reply to the original post (sorry for the confusion):
Maldiv wrote:
Hello,
I have a php update form which use $_POST and $_GET too. I call the update
like this update.php?id=1
And after the user submit the form with new data I use command like this:
UPDATE table SET id=$_POST['id'] WHERE $_GET['id']='1';
This code works on localhost with Apache 2, Win XP, and Php 4.3.5 but it
doesn't works on my real server(Php 4.3.3, Linux, Apache 1.??)
I debuged it and I realised that on localhost I have the correct value in
the $_GET but in remote $_GET is empty.
What can I do?
Thanks!
 

I wonder if track_vars is off in php.ini?  But then, I 
suppose$_POST['id'] would be empty, too.

Anyway, I'd suggest using different names for the GET and POST 
variables.  For instance new_ID for the POST variable. 

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


Re: [PHP] include_once changed behavior?

2004-06-07 Thread Mattias Thorslund
Jason Wong wrote:
Possibly:
manual  Using PHP from the command line  -c switch
From the manual:
The CLI SAPI does not change the current directory to the directory of 
the executed script!

Note: The CGI SAPI supports the CLI SAPI behaviour by means of the -C 
switch when run from the command line. 

In other words, it's possible to make the CGI version work like the CLI 
version (using absolute paths only).  There seems to be no support for 
making CLI work like CGI, however.

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


Re: [PHP] re-keying an array

2004-04-30 Thread Mattias Thorslund
Just a quick follow-up question on that:

Curt Zirzow wrote:

foreach(array_slice($filenames, 0, 2) as $filename) {
 $files[] = path/to/ . $filelname;
}
 

Will a function (such as the array_slice here) in a foreach statement 
get re-evaluated for each iteration, or is it evaluated just once?

In other words, is there anyhing gained by doing:

$short_array = array_slice($filenames, 0, 2);

foreach($short_array as $filename) {
 $files[] = path/to/ . $filelname;
}
/Mattias

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


Re: [PHP] Scripting practices

2004-04-23 Thread Mattias Thorslund
I use precisely what you suggest.  If you later find out you'd like to
wrap a few lines inside a loop, this avoids a potential bug when a
variable is not reset to the initial value for each iteration.


On Fri, 2004-04-23 at 13:55, Gabe wrote:
 When scripting in a language (such as PHP) that doesn't require you to 
 determine the variable type before you use it, is it still considered 
 good technique to initialize it to the type you're going to use it as? 
 Or is it considered ok to just use it?
 
 e.g.
 
 $strText = ;//initialize
 $strText = now i'll give it a useful value;
 
 Or is it just better to skip the first line?  Just curious, thanks!
 
 Gabe

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



[Fwd: [PHP] Search MySQL and Match Whole Words]

2004-04-22 Thread Mattias Thorslund
You mean Full-text searches? Read about them here:

http://dev.mysql.com/doc/mysql/en/Fulltext_Search.html

Only works with certain table types. Not InnoDB tables (transactional) 
for instance.

Best, Mattias

(ps new to this list - messed up on replying first time)

 Original Message 

I was wondering if anyone knows how to do whole word searches in mysql.  I
have a search textbox that users can enter in multiple words to search for
in the database, but things like the mysql LIKE match any part of a word.
Is there a way to search for whole word matches only?  Please let me know if
you can help.
Thanks,

Matt
http://sweetphp.com
--
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