Re: [PHP] After editing only the httpd.conf PHP 5.2.12 works in Apache2.2 on WindowsXP Professional 2002 SP 3, Can this be?

2010-01-05 Thread Jim Lucas

Varuna Seneviratna wrote:

I Edited only the httpd.conf file and the changes I made were
Added: LoadModule php5_module "C:/PHP/php-5.2.12/php5apache2_2.dll"



Yes, this is completely do-able.  If php cannot find a php.ini file, it uses the defaults it was 
compiled with.



Changed DocumentRoot and Directory  from htdocs to test: DocumentRoot
"C:/Program Files/Apache Software Foundation/Apache2.2/test" and 

Added the following
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType image/x-icon .ico
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

There is no php.ini file in PHP installation directory or WINDOWS or
anywhere, there is only the original php.ini-dist and -recommended

But apart from the above PHP works fine.


And also when the URL http://localhost/test is entered the output message is


Not Found

The requested URL /test was not found on this server.



if your DocumentRoot is set to "C:/Program Files/Apache Software Foundation/Apache2.2/test", then 
all you need to do is access http://localhost/  and it will serve up the files from the "C:/Program 
Files/Apache Software Foundation/Apache2.2/test" directory.



But when a file name residing in the test directory is entered the expected
output is given.


Not sure what you mean by this.  Please provide an example.


Why is the set of files in the test directory not listed in the browser
output.



Because you are trying to look for a file or folder called test in the "C:/Program Files/Apache 
Software Foundation/Apache2.2/test" directory.


Jim
--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



[PHP] After editing only the httpd.conf PHP 5.2.12 works in Apache2.2 on WindowsXP Professional 2002 SP 3, Can this be?

2010-01-05 Thread Varuna Seneviratna
I Edited only the httpd.conf file and the changes I made were
Added: LoadModule php5_module "C:/PHP/php-5.2.12/php5apache2_2.dll"

Changed DocumentRoot and Directory  from htdocs to test: DocumentRoot
"C:/Program Files/Apache Software Foundation/Apache2.2/test" and 

Added the following
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType image/x-icon .ico
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

There is no php.ini file in PHP installation directory or WINDOWS or
anywhere, there is only the original php.ini-dist and -recommended

But apart from the above PHP works fine.


And also when the URL http://localhost/test is entered the output message is

> Not Found
>
> The requested URL /test was not found on this server.
>
But when a file name residing in the test directory is entered the expected
output is given.
Why is the set of files in the test directory not listed in the browser
output.


Re: [PHP] pass by reference variable length args

2010-01-05 Thread Robert Cummings

viraj wrote:

if func_get_args supports pass by reference, we could have avoid the
loop and pre-defined arg list.

something like..

extract(func_get_args)   :D


Absolute! I'm not sure why there isn't some kind of way to retrieve a 
reference in this manner, but I suspect it's related to knowing which 
parameters were set as reference appropriate values. For instance 
contrast the following:


bind_stuff( $id, $test );

Versus the following:

bind_stuff( 5, $test );

Defining the function parameters to use references will generate a fatal 
error when 5 is passed since this is a fatal error. How then to enable 
variable args to achieve the same result? I guess one could ask PHP to 
support something like the following:


$args = func_bind_args( array( true, true ) );

Where $args would then contain a reference where the corresponding index 
was set to true in the argument list. Since this isn't very variable, 
then the last index set would denote the default for all other args. 
Thus the example above could be shortened:


$args = func_bind_args( array( true ) );

Or even:

$args = func_bind_args( true );

Since this is run-time too, then PHP could generate an E_WARNING instead 
of E_FATAL and bind a copy instead when no reference was passed.


On further thought, the current func_get_args() could be adapted in this 
manner since it currently accepts no arguments.


Anyways... just thoughts. I hit this problem in the past too :)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] pass by reference variable length args

2010-01-05 Thread viraj
if func_get_args supports pass by reference, we could have avoid the
loop and pre-defined arg list.

something like..

extract(func_get_args)   :D

cheers!

~viraj

On Wed, Jan 6, 2010 at 11:04 AM, viraj  wrote:
> thanks rob!
>
> here goes the working method.
>
> public function bind_result(&$arg1=null,&$arg2=null,&$arg3=null) {
>                $numArgs = func_num_args();
>                $args = array();
>                for ($i=1; $i<= $numArgs; $i++) {
>                         $args['arg' . $i] = &${'arg'.$i};
>                }
>
>                
> call_user_func_array('mysqli_stmt_bind_result',array_merge(array($this->stmt),$args));
> }
>
>        $stmt->bind_result($id, $test);
>        $stmt->fetch();
>        echo $id, $test;
>
> ~viraj
>
>
> On Wed, Jan 6, 2010 at 10:01 AM, Robert Cummings  wrote:
>> viraj wrote:
>>>
>>> hi all,
>>> i'm trying to write a wrapper function for "mysqli_stmt_bind_results".
>>> and expect it to work the same way it accepts and bind results to the
>>> original function.
>>>
>>> the problem is, i couldn't find a way to pass the args by reference
>>> via func_get_args and register the out put from call_user_func_array
>>> to the caller scope.. any idea?
>>>
>>> here goes few lines which i'm trying hard for past 48 hours.. with no
>>> luck.. :(
>>>
>>> class stmt {
>>>       private $stmt;
>>>
>>>       public function bind_result() {
>>>                $argsToBindResult = func_get_args();
>>>                $argList = array($this->stmt);
>>>                $argList = array_merge($argList, $argsToBindResult);
>>>                call_user_func_array('mysqli_stmt_bind_result', $argList);
>>>        }
>>> }
>>>
>>> $stmt->prepare('SELECT name,email FROM users WHERE id = ?');
>>> $stmt->bind_param('i',2);
>>> .. ..
>>> $stmt->bind_result($name,$email);
>>> echo $name,$email;
>>
>> You're out of luck for using the func_get_args() call. The following method
>> (albeit a dirty method) works:
>>
>> >
>> function bind_stuff( &$arg1, &$arg2=null, &$arg3=null, &$arg4=null,
>> &$arg5=null, &$arg6=null, &$arg7=null, &$arg8=null, &$arg9=null )
>> {
>>    for( $i = 1; $i <= 9; $i++ )
>>    {
>>        ${'arg'.$i} = 'bound'.$i;
>>    }
>> }
>>
>> bind_stuff( $name, $email );
>>
>> echo $name."\n";
>> echo $email."\n";
>>
>> ?>
>>
>> Cheers,
>> Rob.
>> --
>> http://www.interjinn.com
>> Application and Templating Framework for PHP
>>
>

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



Re: [PHP] pass by reference variable length args

2010-01-05 Thread viraj
thanks rob!

here goes the working method.

public function bind_result(&$arg1=null,&$arg2=null,&$arg3=null) {
$numArgs = func_num_args();
$args = array();
for ($i=1; $i<= $numArgs; $i++) {
 $args['arg' . $i] = &${'arg'.$i};
}


call_user_func_array('mysqli_stmt_bind_result',array_merge(array($this->stmt),$args));
}

$stmt->bind_result($id, $test);
$stmt->fetch();
echo $id, $test;

~viraj


On Wed, Jan 6, 2010 at 10:01 AM, Robert Cummings  wrote:
> viraj wrote:
>>
>> hi all,
>> i'm trying to write a wrapper function for "mysqli_stmt_bind_results".
>> and expect it to work the same way it accepts and bind results to the
>> original function.
>>
>> the problem is, i couldn't find a way to pass the args by reference
>> via func_get_args and register the out put from call_user_func_array
>> to the caller scope.. any idea?
>>
>> here goes few lines which i'm trying hard for past 48 hours.. with no
>> luck.. :(
>>
>> class stmt {
>>       private $stmt;
>>
>>       public function bind_result() {
>>                $argsToBindResult = func_get_args();
>>                $argList = array($this->stmt);
>>                $argList = array_merge($argList, $argsToBindResult);
>>                call_user_func_array('mysqli_stmt_bind_result', $argList);
>>        }
>> }
>>
>> $stmt->prepare('SELECT name,email FROM users WHERE id = ?');
>> $stmt->bind_param('i',2);
>> .. ..
>> $stmt->bind_result($name,$email);
>> echo $name,$email;
>
> You're out of luck for using the func_get_args() call. The following method
> (albeit a dirty method) works:
>
> 
> function bind_stuff( &$arg1, &$arg2=null, &$arg3=null, &$arg4=null,
> &$arg5=null, &$arg6=null, &$arg7=null, &$arg8=null, &$arg9=null )
> {
>    for( $i = 1; $i <= 9; $i++ )
>    {
>        ${'arg'.$i} = 'bound'.$i;
>    }
> }
>
> bind_stuff( $name, $email );
>
> echo $name."\n";
> echo $email."\n";
>
> ?>
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>

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



Re: [PHP] pass by reference variable length args

2010-01-05 Thread Robert Cummings

viraj wrote:

hi all,
i'm trying to write a wrapper function for "mysqli_stmt_bind_results".
and expect it to work the same way it accepts and bind results to the
original function.

the problem is, i couldn't find a way to pass the args by reference
via func_get_args and register the out put from call_user_func_array
to the caller scope.. any idea?

here goes few lines which i'm trying hard for past 48 hours.. with no luck.. :(

class stmt {
   private $stmt;

   public function bind_result() {
$argsToBindResult = func_get_args();
$argList = array($this->stmt);
$argList = array_merge($argList, $argsToBindResult);
call_user_func_array('mysqli_stmt_bind_result', $argList);
}
}

$stmt->prepare('SELECT name,email FROM users WHERE id = ?');
$stmt->bind_param('i',2);
.. ..
$stmt->bind_result($name,$email);
echo $name,$email;


You're out of luck for using the func_get_args() call. The following 
method (albeit a dirty method) works:


function bind_stuff( &$arg1, &$arg2=null, &$arg3=null, &$arg4=null, 
&$arg5=null, &$arg6=null, &$arg7=null, &$arg8=null, &$arg9=null )

{
for( $i = 1; $i <= 9; $i++ )
{
${'arg'.$i} = 'bound'.$i;
}
}

bind_stuff( $name, $email );

echo $name."\n";
echo $email."\n";

?>

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



[PHP] pass by reference variable length args

2010-01-05 Thread viraj
hi all,
i'm trying to write a wrapper function for "mysqli_stmt_bind_results".
and expect it to work the same way it accepts and bind results to the
original function.

the problem is, i couldn't find a way to pass the args by reference
via func_get_args and register the out put from call_user_func_array
to the caller scope.. any idea?

here goes few lines which i'm trying hard for past 48 hours.. with no luck.. :(

class stmt {
   private $stmt;

   public function bind_result() {
$argsToBindResult = func_get_args();
$argList = array($this->stmt);
$argList = array_merge($argList, $argsToBindResult);
call_user_func_array('mysqli_stmt_bind_result', $argList);
}
}

$stmt->prepare('SELECT name,email FROM users WHERE id = ?');
$stmt->bind_param('i',2);
.. ..
$stmt->bind_result($name,$email);
echo $name,$email;

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



Re: [PHP] How to get a string from C library into PHP via SWIG?

2010-01-05 Thread Eric Fowler
I will expose only one function, prototyped like the foo() example I described.

cstring.i is not implemented for a PHP target (wah).

I think I will go the shell approach. I have enough time in this already.

Eric

On Tue, Jan 5, 2010 at 6:26 PM, Nathan Nobbe  wrote:
> On Tue, Jan 5, 2010 at 4:38 PM, Eric Fowler  wrote:
>>
>> A little more information: my crashes all relate to handling the char
>> datatype. Floats and ints are happy.
>>
>> I suspect that a char type in PHP is not the same as a char type in C.
>> But I am not sure at all.
>>
>> More recently I have used cmalloc.i to allocate arrays of chars and
>> floats. The floats are happy, the chars crash upon allocation.
>
> neat, swig generates php extensions.  i wonder Eric, how much functionality
> you intend to expose to php, a series of functions, classes?  from the
> sounds of your earlier description i would imagine maybe one class or a
> single set of functions to operate on a single string variable, with
> additional parameters for metadata.
> im curious, if youre sold on the generator, or if youre interested to just
> try your hand writing an extension.  if youre strong w/ C you could probly
> crank it out quickly.  another option would be to version the generated
> (swig) C, and repair it by hand, putting those changes in a branch.  during
> subsequent generations, you could merge the work from said branch and
> iterate on that.
> of course the other option is to figure out swig, lol.  anyways, is this C
> of yours for a private project or is it something i could take a peak at; im
> halfway curious what youre working w/.
> o, and guess what, reading through the swig php page, i discovered you can
> write php extensions 'in c++', by creating a thin C wrapper - wow, i had
> never thought of that, lol.
> -nathan

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



Re: [PHP] How to get a string from C library into PHP via SWIG?

2010-01-05 Thread Nathan Nobbe
On Tue, Jan 5, 2010 at 4:38 PM, Eric Fowler  wrote:

> A little more information: my crashes all relate to handling the char
> datatype. Floats and ints are happy.
>
> I suspect that a char type in PHP is not the same as a char type in C.
> But I am not sure at all.
>
> More recently I have used cmalloc.i to allocate arrays of chars and
> floats. The floats are happy, the chars crash upon allocation.
>

neat, swig generates php extensions.  i wonder Eric, how much functionality
you intend to expose to php, a series of functions, classes?  from the
sounds of your earlier description i would imagine maybe one class or a
single set of functions to operate on a single string variable, with
additional parameters for metadata.

im curious, if youre sold on the generator, or if youre interested to just
try your hand writing an extension.  if youre strong w/ C you could probly
crank it out quickly.  another option would be to version the generated
(swig) C, and repair it by hand, putting those changes in a branch.  during
subsequent generations, you could merge the work from said branch and
iterate on that.

of course the other option is to figure out swig, lol.  anyways, is this C
of yours for a private project or is it something i could take a peak at; im
halfway curious what youre working w/.

o, and guess what, reading through the swig php page, i discovered you can
write php extensions 'in c++', by creating a thin C wrapper - wow, i had
never thought of that, lol.

-nathan


Re: [PHP] PHP has encountered an Access Violation at ***

2010-01-05 Thread Robert Cummings

Slack-Moehrle wrote:

Hi All,

Win 2003, PHP 5.2.12 and IIS 6.

I have PHP configured as ISSAPI and it is serving PHP pages. When I try a page 
that requires MySQL I am getting just:

PHP has encountered an Access Violation at (and a RANDOM number)


It means you didn't follow the instructions on the PHP site properly:

http://www.php.net/manual/en/install.windows.iis6.php

Specifically you want to ditch ISAPI and use FastCGI. Additionally, when 
setting up FastCGI in IIS you want to use the NTS build of PHP 
(Non-Thread-Safe). This is VERY important:


http://www.php.net/get/php-5.2.12-nts-win32-installer.msi/from/a/mirror

Then because you'll be pretty screwed for one of the usual bytecode 
caches you'll want to use Microsoft's WinCache bytecode cache for PHP 
FastCGI:


http://www.iis.net/expand/wincacheforphp

After you've done all this, you'll almost certainly find you no longer 
get this error.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



[PHP] PHP has encountered an Access Violation at ***

2010-01-05 Thread Slack-Moehrle
Hi All,

Win 2003, PHP 5.2.12 and IIS 6.

I have PHP configured as ISSAPI and it is serving PHP pages. When I try a page 
that requires MySQL I am getting just:

PHP has encountered an Access Violation at (and a RANDOM number)

What does this mean?

I have mysql extension uncommented in php.ini, iUSR_ has write permissions. I 
have specified the php extension directory in php.ini.

Google has not provided me with results that help me fix.

Does anyone have any thoughts?

-ML

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



Re: [PHP] How to get a string from C library into PHP via SWIG?

2010-01-05 Thread Eric Fowler
A little more information: my crashes all relate to handling the char
datatype. Floats and ints are happy.

I suspect that a char type in PHP is not the same as a char type in C.
But I am not sure at all.

More recently I have used cmalloc.i to allocate arrays of chars and
floats. The floats are happy, the chars crash upon allocation.

Weird.

Eric

On Tue, Jan 5, 2010 at 2:56 PM, Nathan Nobbe  wrote:
> On Tue, Jan 5, 2010 at 3:42 PM, Eric Fowler  wrote:
>>
>> Hm, that could work, but it does produce overhead.
>
> you should consider your overall communication paradigm.  im very loosely
> familiar w/ swig, basically ive heard of it ...
> anyways, you have a few options for communication,
> . shell (call php from C or the other way around)
> . php extension, this may not make sense depending on what your C is doing
> and is by far the most complex
> . network protocol, socket, http or other..
> can you tell us a little bit more about what youre trying to accomplish and
> specifically how C and php are communicating in general in your application?
> -nathan

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



Re: [PHP] How to get a string from C library into PHP via SWIG?

2010-01-05 Thread Eric Fowler
This is going to the list per Nathan's suggestion.

I confess I am doing this the hard way because I want to get a handle
on how to pass across that boundary.

My current angle of attack is to use the malloc.i functions in swig to
handle those strings.

I will keep you all posted. I know you care. :-)

Eric


I have a software library that parses strings into a C language
structure. It is a utility for C programmers.

It contains a utility function that takes the output structure and
formats it as a string for display.

The goal is to demonstrate the functionality by permitting users to
enter strings into a text box and press a button.
The string will be passed into my code, parsed, formatted as a
different kind of string, and returned, where it will be
displayed on the web site.

The code is being shipped as a Windows DLL but for the web site I am
working with Linux dynamic libraries (*.so).
I am able to call functions within the binary from PHP now, but
pointers within PHP are not working far less crossing the
PHP/C Line Of Death without dying.


please keep the responses on list for the benefit of others.

well, if you have an .so, honestly i might spend the effort to wrap it
up in a simple extension.

but if you want to roll something out quickly, i would probly just
invoke it over the shell via shell_exec() or similar.

i cant imagine what sort of noticeable impact you would see in
performance going over the shell in this case.  honestly, i think the
question is how much work do you want to do.  also, do you intend to
share this functionality w/ other php programers, that might be an
argument for an extension.

do you already have a C based program that loads up the library from
the cli and uses STDIN / STDOUT, if so i think going over the shell is
a no-brainer..

On Tue, Jan 5, 2010 at 2:56 PM, Nathan Nobbe  wrote:
> On Tue, Jan 5, 2010 at 3:42 PM, Eric Fowler  wrote:
>>
>> Hm, that could work, but it does produce overhead.
>
> you should consider your overall communication paradigm.  im very loosely
> familiar w/ swig, basically ive heard of it ...
> anyways, you have a few options for communication,
> . shell (call php from C or the other way around)
> . php extension, this may not make sense depending on what your C is doing
> and is by far the most complex
> . network protocol, socket, http or other..
> can you tell us a little bit more about what youre trying to accomplish and
> specifically how C and php are communicating in general in your application?
> -nathan

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



Re: [PHP] How to get a string from C library into PHP via SWIG?

2010-01-05 Thread Nathan Nobbe
On Tue, Jan 5, 2010 at 4:05 PM, Eric Fowler  wrote:

> I have a software library that parses strings into a C language
> structure. It is a utility for C programmers.
>
> It contains a utility function that takes the output structure and
> formats it as a string for display.
>
> The goal is to demonstrate the functionality by permitting users to
> enter strings into a text box and press a button.
> The string will be passed into my code, parsed, formatted as a
> different kind of string, and returned, where it will be
> displayed on the web site.
>
> The code is being shipped as a Windows DLL but for the web site I am
> working with Linux dynamic libraries (*.so).
> I am able to call functions within the binary from PHP now, but
> pointers within PHP are not working far less crossing the
> PHP/C Line Of Death without dying.
>
> Eric


please keep the responses on list for the benefit of others.

well, if you have an .so, honestly i might spend the effort to wrap it up in
a simple extension.

>
but if you want to roll something out quickly, i would probly just invoke it
over the shell via shell_exec() or similar.

>
i cant imagine what sort of noticeable impact you would see in performance
going over the shell in this case.  honestly, i think the question is how
much work do you want
to do.  also, do you intend to share this functionality w/ other php
programers, that might be an argument for an extension.

do you already have a C based program that loads up the library from the cli
and uses STDIN / STDOUT, if so i think going over the shell is a
no-brainer..

-nathan


Re: [PHP] How to get a string from C library into PHP via SWIG?

2010-01-05 Thread Nathan Nobbe
On Tue, Jan 5, 2010 at 3:42 PM, Eric Fowler  wrote:

> Hm, that could work, but it does produce overhead.
>

you should consider your overall communication paradigm.  im very loosely
familiar w/ swig, basically ive heard of it ...

anyways, you have a few options for communication,

. shell (call php from C or the other way around)
. php extension, this may not make sense depending on what your C is doing
and is by far the most complex
. network protocol, socket, http or other..

can you tell us a little bit more about what youre trying to accomplish and
specifically how C and php are communicating in general in your application?

-nathan


Re: [PHP] How to get a string from C library into PHP via SWIG?

2010-01-05 Thread Eric Fowler
Hm, that could work, but it does produce overhead.

Thank you.

Eric

On Tue, Jan 5, 2010 at 1:29 PM, Ashley Sheridan
 wrote:
>
> On Tue, 2010-01-05 at 13:29 -0800, Eric Fowler wrote:
>
> I have a need to call a C language function from a PHP script.
>
> The function, which I wrote, looks like this:
>
> /*
> * foo(): Takes a string in sIn and writes another string into sOut
> according to what is passed in, and the
> * value at *pcch. Will not write more than *pcch bytes to output,
> including null terminator.
> * Upon return, *pcch contains number of chars written to sOut.
> */
> void foo(const char * sIn, char * sOut, size_t * pcch);
>
> So basically I need to pass down a string, and get back a string.
>
> I have been using swig but clearly I ain't getting it (I am good in C
> but new to PHP). Lots of warnings, crashes, and so on. No happiness.
>
> The swig docs show how to pass strings between python, java, etc., and
> C, but nothing on C <---> PHP.
>
> Can anyone help me with a fragment of sample code, or a link?
>
> Thanks
>
> Eric
>
>
> Can't you just compile the C into an executable and call it from a shell? 
> There are several ways to retrieve input from shell programs.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>

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



Re: [PHP] How to get a string from C library into PHP via SWIG?

2010-01-05 Thread Ashley Sheridan
On Tue, 2010-01-05 at 13:29 -0800, Eric Fowler wrote:

> I have a need to call a C language function from a PHP script.
> 
> The function, which I wrote, looks like this:
> 
> /*
> * foo(): Takes a string in sIn and writes another string into sOut
> according to what is passed in, and the
> * value at *pcch. Will not write more than *pcch bytes to output,
> including null terminator.
> * Upon return, *pcch contains number of chars written to sOut.
> */
> void foo(const char * sIn, char * sOut, size_t * pcch);
> 
> So basically I need to pass down a string, and get back a string.
> 
> I have been using swig but clearly I ain't getting it (I am good in C
> but new to PHP). Lots of warnings, crashes, and so on. No happiness.
> 
> The swig docs show how to pass strings between python, java, etc., and
> C, but nothing on C <---> PHP.
> 
> Can anyone help me with a fragment of sample code, or a link?
> 
> Thanks
> 
> Eric
> 


Can't you just compile the C into an executable and call it from a
shell? There are several ways to retrieve input from shell programs.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] How to get a string from C library into PHP via SWIG?

2010-01-05 Thread Eric Fowler
I have a need to call a C language function from a PHP script.

The function, which I wrote, looks like this:

/*
* foo(): Takes a string in sIn and writes another string into sOut
according to what is passed in, and the
* value at *pcch. Will not write more than *pcch bytes to output,
including null terminator.
* Upon return, *pcch contains number of chars written to sOut.
*/
void foo(const char * sIn, char * sOut, size_t * pcch);

So basically I need to pass down a string, and get back a string.

I have been using swig but clearly I ain't getting it (I am good in C
but new to PHP). Lots of warnings, crashes, and so on. No happiness.

The swig docs show how to pass strings between python, java, etc., and
C, but nothing on C <---> PHP.

Can anyone help me with a fragment of sample code, or a link?

Thanks

Eric

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



RE: [PHP] SVG and PHP

2010-01-05 Thread Alice Wei







  
  


On Tue, 2010-01-05 at 15:15 -0500, Alice Wei wrote:



Hi,



  Just went online and saw an SVG generated from Python, and wanted to do the 
similar thing by loading the SVG into an PHP script. Here is the script that I 
have:







The problem is that my screen appears as blank even though I could open up 
USA_Counties_with_FIPS_and_names.svg and see the entire US Map. Does anyone 
know what I might have done wrong here?

Aren't you just opening the file? I think that you need to print it in some way 
suitable to your application.


Try using fread() or other function to read the contents of the file.
 
  Well, I tried, and here is the complete code of the portion I just edited:

#Load the Map
$ourFileName= "USA_Counties_with_FIPS_and_names.svg";
$fh = fopen($ourFileName, "r") or die("Can't open file");
$contents = fread($fh,filesize($ourFileName));
echo $contents;
fclose($fh); 
 
Now I get something on the screen, but still no image: image/svg+xml
Um, is there anything particular I need to put in my code? 


Thanks in advance.



Alice



_

Hotmail: Trusted email with Microsoft’s powerful SPAM protection.

http://clk.atdmt.com/GBL/go/177141664/direct/01/
  
_
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141665/direct/01/




View the source of your browser. Is it showing the SVG code? You need to output 
the correct mime-type headers for the SVG, as by default, PHP outputs headers 
for HTML. Something like this should do the trick:



header("Content-type: image/svg+xml");



This has to occur before any output has already been sent to the browser, 
otherwise you'll get a headers already sent error.


Thanks, this time it does the trick. 





Thanks,

Ash

http://www.ashleysheridan.co.uk







  
_
Hotmail: Free, trusted and rich email service.
http://clk.atdmt.com/GBL/go/171222984/direct/01/

RE: [PHP] SVG and PHP

2010-01-05 Thread Ashley Sheridan
On Tue, 2010-01-05 at 15:15 -0500, Alice Wei wrote:

> 
> 
> Hi,
> 
> 
> 
>   Just went online and saw an SVG generated from Python, and wanted to do the 
> similar thing by loading the SVG into an PHP script. Here is the script that 
> I have:
> 
> 
> 
>  
> 
> 
> #Load the Map
> 
> $ourFileName= "USA_Counties_with_FIPS_and_names.svg";
> 
> $fh = fopen($ourFileName, "r") or die("Can't open file");
> 
> fclose($fh);
> 
> 
> 
> ?>
> 
> 
> 
> The problem is that my screen appears as blank even though I could open up 
> USA_Counties_with_FIPS_and_names.svg and see the entire US Map. Does anyone 
> know what I might have done wrong here?
> 
> Aren't you just opening the file? I think that you need to print it in some 
> way suitable to your application.
> 
> 
> Try using fread() or other function to read the contents of the file.
>  
>   Well, I tried, and here is the complete code of the portion I just edited:
> 
> #Load the Map
> $ourFileName= "USA_Counties_with_FIPS_and_names.svg";
> $fh = fopen($ourFileName, "r") or die("Can't open file");
> $contents = fread($fh,filesize($ourFileName));
> echo $contents;
> fclose($fh); 
>  
> Now I get something on the screen, but still no image: image/svg+xml
> Um, is there anything particular I need to put in my code? 
> 
> 
> Thanks in advance.
> 
> 
> 
> Alice
> 
> 
> 
> _
> 
> Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
> 
> http://clk.atdmt.com/GBL/go/177141664/direct/01/  
>   
> _
> Hotmail: Trusted email with powerful SPAM protection.
> http://clk.atdmt.com/GBL/go/177141665/direct/01/


View the source of your browser. Is it showing the SVG code? You need to
output the correct mime-type headers for the SVG, as by default, PHP
outputs headers for HTML. Something like this should do the trick:

header("Content-type: image/svg+xml");

This has to occur before any output has already been sent to the
browser, otherwise you'll get a headers already sent error.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] SVG and PHP

2010-01-05 Thread Alice Wei



Hi,



  Just went online and saw an SVG generated from Python, and wanted to do the 
similar thing by loading the SVG into an PHP script. Here is the script that I 
have:







The problem is that my screen appears as blank even though I could open up 
USA_Counties_with_FIPS_and_names.svg and see the entire US Map. Does anyone 
know what I might have done wrong here?

Aren't you just opening the file? I think that you need to print it in some way 
suitable to your application.


Try using fread() or other function to read the contents of the file.
 
  Well, I tried, and here is the complete code of the portion I just edited:

#Load the Map
$ourFileName= "USA_Counties_with_FIPS_and_names.svg";
$fh = fopen($ourFileName, "r") or die("Can't open file");
$contents = fread($fh,filesize($ourFileName));
echo $contents;
fclose($fh); 
 
Now I get something on the screen, but still no image: image/svg+xml
Um, is there anything particular I need to put in my code? 


Thanks in advance.



Alice



_

Hotmail: Trusted email with Microsoft’s powerful SPAM protection.

http://clk.atdmt.com/GBL/go/177141664/direct/01/
  
_
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141665/direct/01/

Re: [PHP] SVG and PHP

2010-01-05 Thread Ashley Sheridan
On Tue, 2010-01-05 at 14:57 -0500, Alice Wei wrote:

> Hi, 
> 
>   Just went online and saw an SVG generated from Python, and wanted to do the 
> similar thing by loading the SVG into an PHP script. Here is the script that 
> I have: 
> 
>   
> #Load the Map
> $ourFileName= "USA_Counties_with_FIPS_and_names.svg";
> $fh = fopen($ourFileName, "r") or die("Can't open file");
> fclose($fh); 
> 
> ?>
> 
> The problem is that my screen appears as blank even though I could open up 
> USA_Counties_with_FIPS_and_names.svg and see the entire US Map. Does anyone 
> know what I might have done wrong here? 
> 
> Thanks in advance. 
> 
> Alice
> 
> _
> Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
> http://clk.atdmt.com/GBL/go/177141664/direct/01/


If you go the fopen route, you need to get the contents of the file and
print them out to the browser, with the correct SVG headers. All you're
doing here creating a read-only resource to the file.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] SVG and PHP

2010-01-05 Thread Bruno Fajardo
2010/1/5 Alice Wei 

>
> Hi,
>
>  Just went online and saw an SVG generated from Python, and wanted to do
> the similar thing by loading the SVG into an PHP script. Here is the script
> that I have:
>
> 
> #Load the Map
> $ourFileName= "USA_Counties_with_FIPS_and_names.svg";
> $fh = fopen($ourFileName, "r") or die("Can't open file");
> fclose($fh);
>
> ?>
>
> The problem is that my screen appears as blank even though I could open up
> USA_Counties_with_FIPS_and_names.svg and see the entire US Map. Does anyone
> know what I might have done wrong here?
>

Aren't you just opening the file? I think that you need to print it in some
way suitable to your application.
Try using fread() or other function to read the contents of the file.


>
> Thanks in advance.
>
> Alice
>
> _
> Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
> http://clk.atdmt.com/GBL/go/177141664/direct/01/


[PHP] SVG and PHP

2010-01-05 Thread Alice Wei

Hi, 

  Just went online and saw an SVG generated from Python, and wanted to do the 
similar thing by loading the SVG into an PHP script. Here is the script that I 
have: 



The problem is that my screen appears as blank even though I could open up 
USA_Counties_with_FIPS_and_names.svg and see the entire US Map. Does anyone 
know what I might have done wrong here? 

Thanks in advance. 

Alice
  
_
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141664/direct/01/

Re: [PHP] If design patterns are not supposed to produce reusable code then why use them?

2010-01-05 Thread Bipper Goes!
A pattern is simply a device used to skip out on costly dollars (as opposed
to cheap dollars).  Software development is a low loyalties field.  When new
workers come in and old ones are laid off, or when the project is complete
and you will likely not be working on the project again in the future,
design patterns can be useful.  Loosely stepping withing the confines of a
pattern can be of great benefit (as well as safe a ton of documentation - if
you like leaving assumptions - the mortal enemy of the programmer.).

There are times when I look over project and can pick out a simple, or
sometimes simply anal, programmer.  Forcing square pegs into round holes,
and round holes into diamond pegs.  If you are lost on that, you know the
feeling I get when I try to understand why someone would subject their logic
solely to the pattern.  Like any other system, there needs to be room for
well documented deviations.

This being said, I am a fan of transactional patterns.  A program is like a
city.  While structure is important, the "transactions" amongst it's
denizens are the focus.  While the structure may be able to handle all
transactions at first, growth will likely force expensive and extensive
remodeling.

Tepees vs Skyscrapers, I guess.

This is probably fragmented, but so is my brain right now.  :)


On Mon, Jan 4, 2010 at 8:30 AM, Robert Cummings wrote:

> Richard Quadling wrote:
>
>> 2009/12/30 Tony Marston :
>>
>>> I have recently been engaged in an argument via email with someone who
>>> criticises my low opinion of design patterns (refer to
>>> http://www.tonymarston.net/php-mysql/design-patterns.html ). He says
>>> that
>>> design patterns are merely a convention and not a reusable component. My
>>> argument is that something called a pattern is supposed to have a
>>> recurring
>>> theme, some element of reusability,
>>>
>>
> Design patterns re-use the approach to solving a particular problem set.
> Note that I said approach, because the code may not be re-usable, but the
> tenets of the solution are embodied by the pattern regardless of the
> language used. In this way, design patterns are indeed re-usable. When you
> see that a particular problem falls within the domain of a Design Pattern,
> then the implementation is straightforward since you can use the design
> pattern to guide your implementation.
>
>
>  so that all subsequent implementations
>>> of a pattern should require less effort than the first implementation. If
>>> design patterns do not provide any reusable code then what is the point
>>> of
>>> using them?
>>>
>>
> Each subsequent use of a design pattern should indeed require less effort.
> As you absorb fully the pattern, it becomes easier and easier to  see how
> problems fit within one pattern or another or multiple patterns. Having at
> that point already implemented solutions using design patterns, it should
> become easier each time you create a solution using a previously used design
> pattern.
>
>
>  I do not use design patterns as I consider them to be the wrong level of
>>> abstraction. I am in the business of designing and developing entire
>>> applications which comprise of numerous application transactions, so I
>>> much
>>> prefer to use transaction patterns (refer to
>>> http://www.tonymarston.net/php-mysql/design-patterns-are-dead.html and
>>> http://www.tonymarston.net/php-mysql/transaction-patterns.html ) as
>>> these
>>> provide large amounts of reusable code and are therefore a significant
>>> aid
>>> to programmer productivity.
>>>
>>> What is your opinion? Are design patterns supposed to provide reusable
>>> code
>>> or not? If not, and each implementation of a pattern takes just as much
>>> time
>>> as the first, then where are the productivity gains from using design
>>> patterns?
>>>
>>
> If I ask you to classify bugs by genus, does it not become easier and
> easier to classify any given bug based on your previous experience of
> knowing what constitutes membership in a particular genus? The same is true
> of design patterns.
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


RE: [PHP] Re: splitting a string

2010-01-05 Thread Bob McConnell
From: Shawn McKenzie [mailto:nos...@mckenzies.net] 
> Andrew Ballard wrote:
>> On Tue, Jan 5, 2010 at 10:20 AM, Ashley Sheridan
>>  wrote:
>>> On Tue, 2010-01-05 at 16:18 +0100, Daniel Egeberg wrote:
>>>
 On Tue, Jan 5, 2010 at 16:09, Shawn McKenzie 
wrote:
> Of course this doesn't work for something like
'My.Word.Document.docx'
> or 'archive_v2.0.1.tar.gz', but I don't know what will with
extensions
> being variable length and possibly composed of multiple periods.
 I suppose a solution to that could be having a list of known file
 extensions and use that while falling back to one of the methods
given
 in this thread if there is no match in the list. Of course you
would
 then have to check .tar.gz before .gz if you're just iterating
through
 a list. You might also just choose the longest match (in terms of
 number of periods).

>>>
>>> That was my thought on how operating systems did it. If it maybe
can't
>>> find a matching pattern, then it can fall back to matching anything
>>> after the last period.
>>>
>>> It always puzzles me, because some.archive.tar.gz is a valid file,
but
>>> the extension is .tar.gz and the filename is some.archive. I guess
it
>>> must compare the full filename to a list of knowns, and then try
it's
>>> best after that.
>> 
>> While relying on a file's extension to determine the type of its
>> contents is dangerous, isn't archive.tar.gz just a gzip'd file that
>> happens to contain a tarball named archive.tar? In that case,
wouldn't
>> the correct extension just be .gz?
>> 
>> Andrew
> 
> Yes, or .tgz sometimes.
> 

Most of the time .tgz indicates more than just a gzipped tar file. It
has always been used by Slackware to indicate specific control files
have been added for their package manager.

But that has always been the danger of using the extension instead of
the magic number to identify the file type. Too many extensions have
been overloaded.

Bob McConnell

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



Re: [PHP] Re: splitting a string

2010-01-05 Thread Shawn McKenzie
Andrew Ballard wrote:
> On Tue, Jan 5, 2010 at 10:20 AM, Ashley Sheridan
>  wrote:
>> On Tue, 2010-01-05 at 16:18 +0100, Daniel Egeberg wrote:
>>
>>> On Tue, Jan 5, 2010 at 16:09, Shawn McKenzie  wrote:
 Of course this doesn't work for something like 'My.Word.Document.docx'
 or 'archive_v2.0.1.tar.gz', but I don't know what will with extensions
 being variable length and possibly composed of multiple periods.
>>> I suppose a solution to that could be having a list of known file
>>> extensions and use that while falling back to one of the methods given
>>> in this thread if there is no match in the list. Of course you would
>>> then have to check .tar.gz before .gz if you're just iterating through
>>> a list. You might also just choose the longest match (in terms of
>>> number of periods).
>>>
>>
>> That was my thought on how operating systems did it. If it maybe can't
>> find a matching pattern, then it can fall back to matching anything
>> after the last period.
>>
>> It always puzzles me, because some.archive.tar.gz is a valid file, but
>> the extension is .tar.gz and the filename is some.archive. I guess it
>> must compare the full filename to a list of knowns, and then try it's
>> best after that.
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>>
> 
> While relying on a file's extension to determine the type of its
> contents is dangerous, isn't archive.tar.gz just a gzip'd file that
> happens to contain a tarball named archive.tar? In that case, wouldn't
> the correct extension just be .gz?
> 
> Andrew

Yes, or .tgz sometimes.

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Re: splitting a string

2010-01-05 Thread Andrew Ballard
On Tue, Jan 5, 2010 at 10:20 AM, Ashley Sheridan
 wrote:
> On Tue, 2010-01-05 at 16:18 +0100, Daniel Egeberg wrote:
>
>> On Tue, Jan 5, 2010 at 16:09, Shawn McKenzie  wrote:
>> > Of course this doesn't work for something like 'My.Word.Document.docx'
>> > or 'archive_v2.0.1.tar.gz', but I don't know what will with extensions
>> > being variable length and possibly composed of multiple periods.
>>
>> I suppose a solution to that could be having a list of known file
>> extensions and use that while falling back to one of the methods given
>> in this thread if there is no match in the list. Of course you would
>> then have to check .tar.gz before .gz if you're just iterating through
>> a list. You might also just choose the longest match (in terms of
>> number of periods).
>>
>
>
> That was my thought on how operating systems did it. If it maybe can't
> find a matching pattern, then it can fall back to matching anything
> after the last period.
>
> It always puzzles me, because some.archive.tar.gz is a valid file, but
> the extension is .tar.gz and the filename is some.archive. I guess it
> must compare the full filename to a list of knowns, and then try it's
> best after that.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

While relying on a file's extension to determine the type of its
contents is dangerous, isn't archive.tar.gz just a gzip'd file that
happens to contain a tarball named archive.tar? In that case, wouldn't
the correct extension just be .gz?

Andrew

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



Re: [PHP] Re: splitting a string

2010-01-05 Thread Ashley Sheridan
On Tue, 2010-01-05 at 16:18 +0100, Daniel Egeberg wrote:

> On Tue, Jan 5, 2010 at 16:09, Shawn McKenzie  wrote:
> > Of course this doesn't work for something like 'My.Word.Document.docx'
> > or 'archive_v2.0.1.tar.gz', but I don't know what will with extensions
> > being variable length and possibly composed of multiple periods.
> 
> I suppose a solution to that could be having a list of known file
> extensions and use that while falling back to one of the methods given
> in this thread if there is no match in the list. Of course you would
> then have to check .tar.gz before .gz if you're just iterating through
> a list. You might also just choose the longest match (in terms of
> number of periods).
> 


That was my thought on how operating systems did it. If it maybe can't
find a matching pattern, then it can fall back to matching anything
after the last period.

It always puzzles me, because some.archive.tar.gz is a valid file, but
the extension is .tar.gz and the filename is some.archive. I guess it
must compare the full filename to a list of knowns, and then try it's
best after that.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Re: splitting a string

2010-01-05 Thread Daniel Egeberg
On Tue, Jan 5, 2010 at 16:09, Shawn McKenzie  wrote:
> Of course this doesn't work for something like 'My.Word.Document.docx'
> or 'archive_v2.0.1.tar.gz', but I don't know what will with extensions
> being variable length and possibly composed of multiple periods.

I suppose a solution to that could be having a list of known file
extensions and use that while falling back to one of the methods given
in this thread if there is no match in the list. Of course you would
then have to check .tar.gz before .gz if you're just iterating through
a list. You might also just choose the longest match (in terms of
number of periods).

-- 
Daniel Egeberg

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



Re: [PHP] Re: splitting a string

2010-01-05 Thread Richard Quadling
2010/1/5 Ingleby, Les :
> Hi everyone, thanks so much for your help. The pathinfo($filename, 
> PATHINFO_FILENAME); works a treat for me, since I am dealing and will only be 
> dealing with a word doc then this is awesome.
>
> Still new to PHP but self taught and scripting is coming on hence I don't 
> know many functions just yet.
>
> -Original Message-
> From: Shawn McKenzie [mailto:nos...@mckenzies.net]
> Sent: 05 January 2010 15:09
> To: a...@ashleysheridan.co.uk
> Cc: Ingleby, Les; php-general@lists.php.net
> Subject: Re: [PHP] Re: splitting a string
>
> Ashley Sheridan wrote:
>> On Tue, 2010-01-05 at 08:45 -0600, Shawn McKenzie wrote:
>>
>>> Ingleby, Les wrote:
 Hi all, first time I have posted here so please be nice.

 I am using PEAR HTTP_Upload to handle multiple file uploads. What I need 
 to do is to take the file name which is output using the getProp() 
 function and then remove the file extension from the end of the file for 
 example:

 Original name held in the getProp() array [name] "word_doccument.docx"

 I need to put this into a string such as

 $filename = $props['name'];

 I then need to separate the file name from the file extension.

 I have been reading the php manual do please don't bother referring me to 
 that.

 Thanks in advance.

 LEGAL INFORMATION
 Information contained in this e-mail may be subject to public disclosure 
 under the Freedom of Information Act 2000. Unless the information is 
 legally exempt, the confidentiality of this e-mail and your reply cannot 
 be guaranteed.
 Unless expressly stated otherwise, the information contained in this 
 e-mail & any files transmitted with it are intended for the recipient 
 only. If you are not the intended recipient you must not copy, distribute, 
 or take any action or reliance upon it. If you have received this e-mail 
 in error, you should notify the sender immediately and delete this email. 
 Any unauthorised disclosure of the information contained in this e-mail is 
 strictly prohibited.  Any views or opinions presented are solely those of 
 the author and do not necessarily represent those of Tyne Metropolitan 
 College unless explicitly stated otherwise.
 This e-mail and attachments have been scanned for viruses prior to leaving 
 Tyne Metropolitan College. Tyne Metropolitan College will not be liable 
 for any losses as a result of any viruses being passed on.

>>> list($filename) = explode('.', $props['name']);
>>>
>>> Or if you may need the extension:
>>>
>>> list($filename, $extension) = explode('.', $props['name']);
>>>
>>> --
>>> Thanks!
>>> -Shawn
>>> http://www.spidean.com
>>>
>>
>>
>> I just though. How would all these methods fare when given a file like
>> archive.tar.gz, where the .tar.gz is the full extension, not just
>> the .gz?
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>
> Well I thought about that when I posted.  If all you're concerned about
> is the filename then my first example works great, for the second to get
> the full extension you would set a limit to only return the first part
> before the . and then all the rest (assuming that the rest is the
> extension):
>
> list($filename, $extension) = explode('.', 'archive.tar.gz', 2);
>
> Of course this doesn't work for something like 'My.Word.Document.docx'
> or 'archive_v2.0.1.tar.gz', but I don't know what will with extensions
> being variable length and possibly composed of multiple periods.
>
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
> LEGAL INFORMATION
> Information contained in this e-mail may be subject to public disclosure 
> under the Freedom of Information Act 2000. Unless the information is legally 
> exempt, the confidentiality of this e-mail and your reply cannot be 
> guaranteed.
> Unless expressly stated otherwise, the information contained in this e-mail & 
> any files transmitted with it are intended for the recipient only. If you are 
> not the intended recipient you must not copy, distribute, or take any action 
> or reliance upon it. If you have received this e-mail in error, you should 
> notify the sender immediately and delete this email. Any unauthorised 
> disclosure of the information contained in this e-mail is strictly 
> prohibited.  Any views or opinions presented are solely those of the author 
> and do not necessarily represent those of Tyne Metropolitan College unless 
> explicitly stated otherwise.
> This e-mail and attachments have been scanned for viruses prior to leaving 
> Tyne Metropolitan College. Tyne Metropolitan College will not be liable for 
> any losses as a result of any viruses being passed on.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Make sure you check out the documentation at http://www.php.net/manual/en.

You can use http://www.php.net/funct

RE: [PHP] Re: splitting a string

2010-01-05 Thread Ingleby, Les
Hi everyone, thanks so much for your help. The pathinfo($filename, 
PATHINFO_FILENAME); works a treat for me, since I am dealing and will only be 
dealing with a word doc then this is awesome.

Still new to PHP but self taught and scripting is coming on hence I don't know 
many functions just yet.

-Original Message-
From: Shawn McKenzie [mailto:nos...@mckenzies.net] 
Sent: 05 January 2010 15:09
To: a...@ashleysheridan.co.uk
Cc: Ingleby, Les; php-general@lists.php.net
Subject: Re: [PHP] Re: splitting a string

Ashley Sheridan wrote:
> On Tue, 2010-01-05 at 08:45 -0600, Shawn McKenzie wrote:
> 
>> Ingleby, Les wrote:
>>> Hi all, first time I have posted here so please be nice.
>>>
>>> I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to 
>>> do is to take the file name which is output using the getProp() function 
>>> and then remove the file extension from the end of the file for example:
>>>
>>> Original name held in the getProp() array [name] "word_doccument.docx"
>>>
>>> I need to put this into a string such as
>>>
>>> $filename = $props['name'];
>>>
>>> I then need to separate the file name from the file extension.
>>>
>>> I have been reading the php manual do please don't bother referring me to 
>>> that.
>>>
>>> Thanks in advance.
>>>
>>> LEGAL INFORMATION
>>> Information contained in this e-mail may be subject to public disclosure 
>>> under the Freedom of Information Act 2000. Unless the information is 
>>> legally exempt, the confidentiality of this e-mail and your reply cannot be 
>>> guaranteed. 
>>> Unless expressly stated otherwise, the information contained in this e-mail 
>>> & any files transmitted with it are intended for the recipient only. If you 
>>> are not the intended recipient you must not copy, distribute, or take any 
>>> action or reliance upon it. If you have received this e-mail in error, you 
>>> should notify the sender immediately and delete this email. Any 
>>> unauthorised disclosure of the information contained in this e-mail is 
>>> strictly prohibited.  Any views or opinions presented are solely those of 
>>> the author and do not necessarily represent those of Tyne Metropolitan 
>>> College unless explicitly stated otherwise.
>>> This e-mail and attachments have been scanned for viruses prior to leaving 
>>> Tyne Metropolitan College. Tyne Metropolitan College will not be liable for 
>>> any losses as a result of any viruses being passed on.
>>>
>> list($filename) = explode('.', $props['name']);
>>
>> Or if you may need the extension:
>>
>> list($filename, $extension) = explode('.', $props['name']);
>>
>> -- 
>> Thanks!
>> -Shawn
>> http://www.spidean.com
>>
> 
> 
> I just though. How would all these methods fare when given a file like
> archive.tar.gz, where the .tar.gz is the full extension, not just
> the .gz?
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 

Well I thought about that when I posted.  If all you're concerned about
is the filename then my first example works great, for the second to get
the full extension you would set a limit to only return the first part
before the . and then all the rest (assuming that the rest is the
extension):

list($filename, $extension) = explode('.', 'archive.tar.gz', 2);

Of course this doesn't work for something like 'My.Word.Document.docx'
or 'archive_v2.0.1.tar.gz', but I don't know what will with extensions
being variable length and possibly composed of multiple periods.


-- 
Thanks!
-Shawn
http://www.spidean.com

LEGAL INFORMATION
Information contained in this e-mail may be subject to public disclosure under 
the Freedom of Information Act 2000. Unless the information is legally exempt, 
the confidentiality of this e-mail and your reply cannot be guaranteed. 
Unless expressly stated otherwise, the information contained in this e-mail & 
any files transmitted with it are intended for the recipient only. If you are 
not the intended recipient you must not copy, distribute, or take any action or 
reliance upon it. If you have received this e-mail in error, you should notify 
the sender immediately and delete this email. Any unauthorised disclosure of 
the information contained in this e-mail is strictly prohibited.  Any views or 
opinions presented are solely those of the author and do not necessarily 
represent those of Tyne Metropolitan College unless explicitly stated otherwise.
This e-mail and attachments have been scanned for viruses prior to leaving Tyne 
Metropolitan College. Tyne Metropolitan College will not be liable for any 
losses as a result of any viruses being passed on.

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



Re: [PHP] Re: splitting a string

2010-01-05 Thread Shawn McKenzie
Ashley Sheridan wrote:
> On Tue, 2010-01-05 at 08:45 -0600, Shawn McKenzie wrote:
> 
>> Ingleby, Les wrote:
>>> Hi all, first time I have posted here so please be nice.
>>>
>>> I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to 
>>> do is to take the file name which is output using the getProp() function 
>>> and then remove the file extension from the end of the file for example:
>>>
>>> Original name held in the getProp() array [name] "word_doccument.docx"
>>>
>>> I need to put this into a string such as
>>>
>>> $filename = $props['name'];
>>>
>>> I then need to separate the file name from the file extension.
>>>
>>> I have been reading the php manual do please don't bother referring me to 
>>> that.
>>>
>>> Thanks in advance.
>>>
>>> LEGAL INFORMATION
>>> Information contained in this e-mail may be subject to public disclosure 
>>> under the Freedom of Information Act 2000. Unless the information is 
>>> legally exempt, the confidentiality of this e-mail and your reply cannot be 
>>> guaranteed. 
>>> Unless expressly stated otherwise, the information contained in this e-mail 
>>> & any files transmitted with it are intended for the recipient only. If you 
>>> are not the intended recipient you must not copy, distribute, or take any 
>>> action or reliance upon it. If you have received this e-mail in error, you 
>>> should notify the sender immediately and delete this email. Any 
>>> unauthorised disclosure of the information contained in this e-mail is 
>>> strictly prohibited.  Any views or opinions presented are solely those of 
>>> the author and do not necessarily represent those of Tyne Metropolitan 
>>> College unless explicitly stated otherwise.
>>> This e-mail and attachments have been scanned for viruses prior to leaving 
>>> Tyne Metropolitan College. Tyne Metropolitan College will not be liable for 
>>> any losses as a result of any viruses being passed on.
>>>
>> list($filename) = explode('.', $props['name']);
>>
>> Or if you may need the extension:
>>
>> list($filename, $extension) = explode('.', $props['name']);
>>
>> -- 
>> Thanks!
>> -Shawn
>> http://www.spidean.com
>>
> 
> 
> I just though. How would all these methods fare when given a file like
> archive.tar.gz, where the .tar.gz is the full extension, not just
> the .gz?
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 

Well I thought about that when I posted.  If all you're concerned about
is the filename then my first example works great, for the second to get
the full extension you would set a limit to only return the first part
before the . and then all the rest (assuming that the rest is the
extension):

list($filename, $extension) = explode('.', 'archive.tar.gz', 2);

Of course this doesn't work for something like 'My.Word.Document.docx'
or 'archive_v2.0.1.tar.gz', but I don't know what will with extensions
being variable length and possibly composed of multiple periods.


-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Re: splitting a string

2010-01-05 Thread Richard Quadling
2010/1/5 Ashley Sheridan :
> On Tue, 2010-01-05 at 08:45 -0600, Shawn McKenzie wrote:
>
>> Ingleby, Les wrote:
>> > Hi all, first time I have posted here so please be nice.
>> >
>> > I am using PEAR HTTP_Upload to handle multiple file uploads. What I need 
>> > to do is to take the file name which is output using the getProp() 
>> > function and then remove the file extension from the end of the file for 
>> > example:
>> >
>> > Original name held in the getProp() array [name] "word_doccument.docx"
>> >
>> > I need to put this into a string such as
>> >
>> > $filename = $props['name'];
>> >
>> > I then need to separate the file name from the file extension.
>> >
>> > I have been reading the php manual do please don't bother referring me to 
>> > that.
>> >
>> > Thanks in advance.
>> >
>> > LEGAL INFORMATION
>> > Information contained in this e-mail may be subject to public disclosure 
>> > under the Freedom of Information Act 2000. Unless the information is 
>> > legally exempt, the confidentiality of this e-mail and your reply cannot 
>> > be guaranteed.
>> > Unless expressly stated otherwise, the information contained in this 
>> > e-mail & any files transmitted with it are intended for the recipient 
>> > only. If you are not the intended recipient you must not copy, distribute, 
>> > or take any action or reliance upon it. If you have received this e-mail 
>> > in error, you should notify the sender immediately and delete this email. 
>> > Any unauthorised disclosure of the information contained in this e-mail is 
>> > strictly prohibited.  Any views or opinions presented are solely those of 
>> > the author and do not necessarily represent those of Tyne Metropolitan 
>> > College unless explicitly stated otherwise.
>> > This e-mail and attachments have been scanned for viruses prior to leaving 
>> > Tyne Metropolitan College. Tyne Metropolitan College will not be liable 
>> > for any losses as a result of any viruses being passed on.
>> >
>>
>> list($filename) = explode('.', $props['name']);
>>
>> Or if you may need the extension:
>>
>> list($filename, $extension) = explode('.', $props['name']);
>>
>> --
>> Thanks!
>> -Shawn
>> http://www.spidean.com
>>
>
>
> I just though. How would all these methods fare when given a file like
> archive.tar.gz, where the .tar.gz is the full extension, not just
> the .gz?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>



outputs ...

Original : archve.tar.gz
Pathinfo : archve.tar / gz
Substr (right)   : archve.tar / .gz
Substr (left): archve / .tar.gz
List : archve / tar


The only option that seems to be working here (and one that wasn't
previously suggested) is to use

$substr_left_name  = substr($file, 0, strpos($file, '.'));
$substr_left_extension = substr($file, strpos($file, '.'));



-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Re: splitting a string

2010-01-05 Thread Ashley Sheridan
On Tue, 2010-01-05 at 08:45 -0600, Shawn McKenzie wrote:

> Ingleby, Les wrote:
> > Hi all, first time I have posted here so please be nice.
> > 
> > I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to 
> > do is to take the file name which is output using the getProp() function 
> > and then remove the file extension from the end of the file for example:
> > 
> > Original name held in the getProp() array [name] "word_doccument.docx"
> > 
> > I need to put this into a string such as
> > 
> > $filename = $props['name'];
> > 
> > I then need to separate the file name from the file extension.
> > 
> > I have been reading the php manual do please don't bother referring me to 
> > that.
> > 
> > Thanks in advance.
> > 
> > LEGAL INFORMATION
> > Information contained in this e-mail may be subject to public disclosure 
> > under the Freedom of Information Act 2000. Unless the information is 
> > legally exempt, the confidentiality of this e-mail and your reply cannot be 
> > guaranteed. 
> > Unless expressly stated otherwise, the information contained in this e-mail 
> > & any files transmitted with it are intended for the recipient only. If you 
> > are not the intended recipient you must not copy, distribute, or take any 
> > action or reliance upon it. If you have received this e-mail in error, you 
> > should notify the sender immediately and delete this email. Any 
> > unauthorised disclosure of the information contained in this e-mail is 
> > strictly prohibited.  Any views or opinions presented are solely those of 
> > the author and do not necessarily represent those of Tyne Metropolitan 
> > College unless explicitly stated otherwise.
> > This e-mail and attachments have been scanned for viruses prior to leaving 
> > Tyne Metropolitan College. Tyne Metropolitan College will not be liable for 
> > any losses as a result of any viruses being passed on.
> > 
> 
> list($filename) = explode('.', $props['name']);
> 
> Or if you may need the extension:
> 
> list($filename, $extension) = explode('.', $props['name']);
> 
> -- 
> Thanks!
> -Shawn
> http://www.spidean.com
> 


I just though. How would all these methods fare when given a file like
archive.tar.gz, where the .tar.gz is the full extension, not just
the .gz?

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Re: splitting a string

2010-01-05 Thread Shawn McKenzie
Ingleby, Les wrote:
> Hi all, first time I have posted here so please be nice.
> 
> I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to 
> do is to take the file name which is output using the getProp() function and 
> then remove the file extension from the end of the file for example:
> 
> Original name held in the getProp() array [name] "word_doccument.docx"
> 
> I need to put this into a string such as
> 
> $filename = $props['name'];
> 
> I then need to separate the file name from the file extension.
> 
> I have been reading the php manual do please don't bother referring me to 
> that.
> 
> Thanks in advance.
> 
> LEGAL INFORMATION
> Information contained in this e-mail may be subject to public disclosure 
> under the Freedom of Information Act 2000. Unless the information is legally 
> exempt, the confidentiality of this e-mail and your reply cannot be 
> guaranteed. 
> Unless expressly stated otherwise, the information contained in this e-mail & 
> any files transmitted with it are intended for the recipient only. If you are 
> not the intended recipient you must not copy, distribute, or take any action 
> or reliance upon it. If you have received this e-mail in error, you should 
> notify the sender immediately and delete this email. Any unauthorised 
> disclosure of the information contained in this e-mail is strictly 
> prohibited.  Any views or opinions presented are solely those of the author 
> and do not necessarily represent those of Tyne Metropolitan College unless 
> explicitly stated otherwise.
> This e-mail and attachments have been scanned for viruses prior to leaving 
> Tyne Metropolitan College. Tyne Metropolitan College will not be liable for 
> any losses as a result of any viruses being passed on.
> 

list($filename) = explode('.', $props['name']);

Or if you may need the extension:

list($filename, $extension) = explode('.', $props['name']);

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] splitting a string

2010-01-05 Thread Ashley Sheridan
On Tue, 2010-01-05 at 14:26 +0100, Daniel Egeberg wrote:

> On Tue, Jan 5, 2010 at 14:13, Ashley Sheridan  
> wrote:
> > (untested - I always forget the order of the params!)
> 
> As a general rule, string functions are always haystack-needle and
> array functions are always needle-haystack. I can't think of any
> exceptions to that rule.
> 
> -- 
> Daniel Egeberg
> 


Thanks! I'll try and remember that. It'll save me many trips to the
manual pages as well!

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] splitting a string

2010-01-05 Thread Daniel Egeberg
On Tue, Jan 5, 2010 at 14:13, Ashley Sheridan  wrote:
> (untested - I always forget the order of the params!)

As a general rule, string functions are always haystack-needle and
array functions are always needle-haystack. I can't think of any
exceptions to that rule.

-- 
Daniel Egeberg

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



Re: [PHP] splitting a string

2010-01-05 Thread Ashley Sheridan
On Tue, 2010-01-05 at 12:39 +, Ingleby, Les wrote:

> Hi all, first time I have posted here so please be nice.
> 
> I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to 
> do is to take the file name which is output using the getProp() function and 
> then remove the file extension from the end of the file for example:
> 
> Original name held in the getProp() array [name] "word_doccument.docx"
> 
> I need to put this into a string such as
> 
> $filename = $props['name'];
> 
> I then need to separate the file name from the file extension.
> 
> I have been reading the php manual do please don't bother referring me to 
> that.
> 
> Thanks in advance.
> 
> LEGAL INFORMATION
> Information contained in this e-mail may be subject to public disclosure 
> under the Freedom of Information Act 2000. Unless the information is legally 
> exempt, the confidentiality of this e-mail and your reply cannot be 
> guaranteed. 
> Unless expressly stated otherwise, the information contained in this e-mail & 
> any files transmitted with it are intended for the recipient only. If you are 
> not the intended recipient you must not copy, distribute, or take any action 
> or reliance upon it. If you have received this e-mail in error, you should 
> notify the sender immediately and delete this email. Any unauthorised 
> disclosure of the information contained in this e-mail is strictly 
> prohibited.  Any views or opinions presented are solely those of the author 
> and do not necessarily represent those of Tyne Metropolitan College unless 
> explicitly stated otherwise.
> This e-mail and attachments have been scanned for viruses prior to leaving 
> Tyne Metropolitan College. Tyne Metropolitan College will not be liable for 
> any losses as a result of any viruses being passed on.


PHPBB uses the substr() function along with the strrpos() function to
grab the extension from a file. You could do something like this:
(untested - I always forget the order of the params!)

$name = substr($filename, 0, strrpos($filename, '.'));

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] splitting a string

2010-01-05 Thread Daniel Egeberg
On Tue, Jan 5, 2010 at 13:39, Ingleby, Les  wrote:
> Hi all, first time I have posted here so please be nice.
>
> I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to 
> do is to take the file name which is output using the getProp() function and 
> then remove the file extension from the end of the file for example:
>
> Original name held in the getProp() array [name] "word_doccument.docx"
>
> I need to put this into a string such as
>
> $filename = $props['name'];
>
> I then need to separate the file name from the file extension.
>
> I have been reading the php manual do please don't bother referring me to 
> that.
>
> Thanks in advance.

There are a couple of ways you could do this. The most straightforward
way would be to use the pathinfo() function.



See http://php.net/pathinfo for more information about that function.

You could also explode() it and do something with that, or you could
or use some of the other many string manipulation functions. I think
pathinfo() is easiest.

-- 
Daniel Egeberg

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



[PHP] splitting a string

2010-01-05 Thread Ingleby, Les
Hi all, first time I have posted here so please be nice.

I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to do 
is to take the file name which is output using the getProp() function and then 
remove the file extension from the end of the file for example:

Original name held in the getProp() array [name] "word_doccument.docx"

I need to put this into a string such as

$filename = $props['name'];

I then need to separate the file name from the file extension.

I have been reading the php manual do please don't bother referring me to that.

Thanks in advance.

LEGAL INFORMATION
Information contained in this e-mail may be subject to public disclosure under 
the Freedom of Information Act 2000. Unless the information is legally exempt, 
the confidentiality of this e-mail and your reply cannot be guaranteed. 
Unless expressly stated otherwise, the information contained in this e-mail & 
any files transmitted with it are intended for the recipient only. If you are 
not the intended recipient you must not copy, distribute, or take any action or 
reliance upon it. If you have received this e-mail in error, you should notify 
the sender immediately and delete this email. Any unauthorised disclosure of 
the information contained in this e-mail is strictly prohibited.  Any views or 
opinions presented are solely those of the author and do not necessarily 
represent those of Tyne Metropolitan College unless explicitly stated otherwise.
This e-mail and attachments have been scanned for viruses prior to leaving Tyne 
Metropolitan College. Tyne Metropolitan College will not be liable for any 
losses as a result of any viruses being passed on.


Re: [PHP] Luhn (modulo 10) check digit calculator

2010-01-05 Thread Richard Quadling
2010/1/5 Richard Quadling :
> 2010/1/5 Angus Mann :
>> Hi all. Perhaps a lazy request, but does anybody have some cut-n-paste code 
>> to calculate a Luhn check-digit?
>>
>> It's a check-digit often added to the end of things like credit card or 
>> account numbers to make detecting typo's a bit easier.
>>
>> I found lots of code to validate a number once the check-digit is applied, 
>> but nothing to calculate the digit in the first place.
>>
>> Thanks in advance !
>> Angus
>>
>>
>
> Modified version found at
> http://blog.planzero.org/2009/08/luhn-modulus-implementation-php/
>
>  /* Luhn algorithm number checker - (c) 2005-2008 - planzero.org            *
>  * This code has been released into the public domain, however please      *
>  * give credit to the original author where possible.                      */
>
> function luhn_check($number) {
>  // If the total mod 10 equals 0, the number is valid
>  return (luhn_process($number) % 10 == 0) ? TRUE : FALSE;
>
> }
>
> function luhn_process($number) {
>
>  // Strip any non-digits (useful for credit card numbers with spaces
> and hyphens)
>  $number=preg_replace('/\D/', '', $number);
>
>  // Set the string length and parity
>  $number_length=strlen($number);
>  $parity=$number_length % 2;
>
>  // Loop through each digit and do the maths
>  $total=0;
>  for ($i=0; $i<$number_length; $i++) {
>    $digit=$number[$i];
>    // Multiply alternate digits by two
>    if ($i % 2 == $parity) {
>      $digit*=2;
>      // If the sum is two digits, add them together (in effect)
>      if ($digit > 9) {
>        $digit-=9;
>      }
>    }
>    // Total up the digits
>    $total+=$digit;
>  }
>
>  return $total;
> }
>
> function luhn_checkdigit($number) {
>  return 10 - (luhn_process($number . '0') % 20);
> }
>
>
> echo '49927398716 is ', (luhn_check('49927398716') ? 'Valid' :
> 'Invalid'), PHP_EOL;
> echo 'The check digit for 4992739871 is ',
> luhn_checkdigit('4992739871'), PHP_EOL;
> ?>
>
>
> outputs ...
>
> 49927398716 is Valid
> The check digit for 4992739871 is 6
>
>
>
> --
> -
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>

And that 20 is a typo. Sorry.

function luhn_checkdigit($number) {
  return 10 - (luhn_process($number . '0') % 10);
}



-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Luhn (modulo 10) check digit calculator

2010-01-05 Thread Richard Quadling
2010/1/5 Angus Mann :
> Hi all. Perhaps a lazy request, but does anybody have some cut-n-paste code 
> to calculate a Luhn check-digit?
>
> It's a check-digit often added to the end of things like credit card or 
> account numbers to make detecting typo's a bit easier.
>
> I found lots of code to validate a number once the check-digit is applied, 
> but nothing to calculate the digit in the first place.
>
> Thanks in advance !
> Angus
>
>

Modified version found at
http://blog.planzero.org/2009/08/luhn-modulus-implementation-php/

 9) {
$digit-=9;
  }
}
// Total up the digits
$total+=$digit;
  }

  return $total;
}

function luhn_checkdigit($number) {
  return 10 - (luhn_process($number . '0') % 20);
}


echo '49927398716 is ', (luhn_check('49927398716') ? 'Valid' :
'Invalid'), PHP_EOL;
echo 'The check digit for 4992739871 is ',
luhn_checkdigit('4992739871'), PHP_EOL;
?>


outputs ...

49927398716 is Valid
The check digit for 4992739871 is 6



-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Luhn (modulo 10) check digit calculator

2010-01-05 Thread Per Jessen
Angus Mann wrote:

> Hi all. Perhaps a lazy request, but does anybody have some cut-n-paste
> code to calculate a Luhn check-digit?
> 

http://de.wikipedia.org/wiki/Luhn-Algorithmus

(several examples, including one in PHP).


/Per

-- 
Per Jessen, Zürich (0.0°C)


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



[PHP] Luhn (modulo 10) check digit calculator

2010-01-05 Thread Angus Mann
Hi all. Perhaps a lazy request, but does anybody have some cut-n-paste code to 
calculate a Luhn check-digit?

It's a check-digit often added to the end of things like credit card or account 
numbers to make detecting typo's a bit easier.

I found lots of code to validate a number once the check-digit is applied, but 
nothing to calculate the digit in the first place.

Thanks in advance !
Angus



Re: [PHP] What is the difference between the two streams 5.3 and 5.2 versions and What is the need for maintaining two streams?

2010-01-05 Thread Daniel Egeberg
On Tue, Jan 5, 2010 at 10:34, Daniel Egeberg  wrote:
> On Tue, Jan 5, 2010 at 02:22, Varuna Seneviratna  wrote:
>> Since there are two stable versions 5.3 and 5.2 .What is the difference
>> between these two streams and What is the need for maintaining two streams?
>
> The PHP 5.3.x branch is still pretty new. That is why 5.2.x is still
> maintained to provide bug fixes and security patches seeing as there
> are still a lot of people using that branch.
>
> If you are going to do a new install, PHP 5.3.1 should be just fine for you.

And that was supposed to have gone to the list as well. Sorry. Hit the
wrong button.

-- 
Daniel Egeberg

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