Re: [PHP] PHP and curl

2013-09-26 Thread Shawn McKenzie
Unfortunately this isn't anything to do with PHP.  I don't have any info on
the app, what it's supposed to return or what the parameter passed should
be.  The PHP soap call is working, but the app isn't returning what you
want or expect I guess.


On Thu, Sep 26, 2013 at 8:36 AM, Alf Stockton a...@stockton.co.za wrote:

  Shawn, that was silly of me. I have now removed the echo but I still do
 not get the expected result from the server.
 var_dump of $result returns:-

 object(stdClass)#2 (1) {
   [GetSequenceNoResult]=
   object(stdClass)#3 (6) {
 [iServerNo]=
 int(0)
 [iClientNo]=
 int(0)
 [bNoLimitDownload]=
 bool(false)
 [dtStartDate]=
 string(19) 0001-01-01T00:00:00
 [dtEndDate]=
 string(19) 0001-01-01T00:00:00
 [dtServerTime]=
 string(19) 0001-01-01T00:00:00
   }
 }

 whereas the expected result is to have each of those fields containing
 data.
 My code now looks like

 ?php
 $strTerminalname = CIS;
 $version = 1.2;
 $client = new SoapClient(
 http://192.168.0.10/CISWebService/Mediamanager.asmx?WSDL;http://192.168.0.10/CISWebService/Mediamanager.asmx?WSDL
 );
 $result = $client-GetSequenceNo($strTerminalname);
 print_r($result);
 var_dump($result);
 ?


 On 25/09/13 17:23, Shawn McKenzie wrote:

 $result = $client-GetSequenceNo( CIS ); shouldn't be throwing that
 error.  Maybe you are trying to do something with $result afterwards?  Try
 var_dump($result);


 On Wed, Sep 25, 2013 at 10:12 AM, Alf Stockton a...@stockton.co.za wrote:


 On 25/09/13 16:52, Shawn McKenzie wrote:

 $client-GetSequenceNo( $parameters );

 That unfortunately returns

 alf@alf-ThinkPad-T500:~/Development/PHP/DevIt$ php
 php-soap-web-service.php  test.txt
 PHP Catchable fatal error:  Object of class stdClass could not be
 converted to string in
 /home/alf/Development/PHP/DevIt/php-soap-web-service.php on line 7

 No matter if I use
 $result = $client-GetSequenceNo( CIS );
 or
 $result = $client-GetSequenceNo($strTerminalname);




 --

 Regards,
 Alf Stockton  www.stockton.co.za




  --
  --
 Thanks!
 -Shawn
 --


 --

 Regards,
 Alf Stockton  www.stockton.co.za




-- 
Thanks!
-Shawn


Re: [PHP] PHP and curl

2013-09-25 Thread Shawn McKenzie
SOAP functions can be called as methods of the SoapClient object.  Maybe:

$client-GetSequenceNo( $parameters );

-Shawn


On Wed, Sep 25, 2013 at 9:17 AM, Alf Stockton a...@stockton.co.za wrote:

 In an attempt to interface with a webservice on a Windows 7 server I have
 started writing the following:-
 [code]
 ?php
 $strTerminalname = CIS;
 $version = 1.2;
 $client = new SoapClient(http://192.168.0.**
 10/CISWebService/Mediamanager.**asmx?WSDLhttp://192.168.0.10/CISWebService/Mediamanager.asmx?WSDL
 );
 var_dump($client-__**getFunctions());
 $result = 
 $client-__doRequest(**GetSequenceNo,$**strTerminalname,$version,
 $one_way = 0);
 ?
 [/code]
 and I execute it via
 php php-soap-web-service.php  test.txt
 on my Ubuntu 13.04 laptop using php version Zend Engine v2.4.0
 in return I get
 array(20) {
   [0]=
   string(59) GetMediaListResponse GetMediaList(GetMediaList $parameters)
   [1]=
   string(68) GetMediaListAllResponse GetMediaListAll(**GetMediaListAll
 $parameters)
   [2]=
   string(59) GetSoundListResponse GetSoundList(GetSoundList $parameters)
   [3]=
   string(77) GetTerminalDataXMLResponse 
 GetTerminalDataXML(**GetTerminalDataXML
 $parameters)
   [4]=
   string(59) GetRouterXmlResponse GetRouterXml(GetRouterXml $parameters)
   [5]=
   string(80) GetTerminalSoundXMLResponse 
 GetTerminalSoundXML(**GetTerminalSoundXML
 $parameters)
   [6]=
   string(62) SetSequenceNoResponse SetSequenceNo(SetSequenceNo
 $parameters)
   [7]=
   string(50) GetConfigResponse GetConfig(GetConfig $parameters)
   [8]=
   string(62) GetSequenceNoResponse GetSequenceNo(GetSequenceNo
 $parameters)
   [9]=
   string(95) **UpdateClientMediaLogTimeRespon**se
 UpdateClientMediaLogTime(**UpdateClientMediaLogTime $parameters)
   [10]=
   string(59) GetMediaListResponse GetMediaList(GetMediaList $parameters)
   [11]=
   string(68) GetMediaListAllResponse GetMediaListAll(**GetMediaListAll
 $parameters)
   [12]=
   string(59) GetSoundListResponse GetSoundList(GetSoundList $parameters)
   [13]=
   string(77) GetTerminalDataXMLResponse 
 GetTerminalDataXML(**GetTerminalDataXML
 $parameters)
   [14]=
   string(59) GetRouterXmlResponse GetRouterXml(GetRouterXml $parameters)
   [15]=
   string(80) GetTerminalSoundXMLResponse 
 GetTerminalSoundXML(**GetTerminalSoundXML
 $parameters)
   [16]=
   string(62) SetSequenceNoResponse SetSequenceNo(SetSequenceNo
 $parameters)
   [17]=
   string(50) GetConfigResponse GetConfig(GetConfig $parameters)
   [18]=
   string(62) GetSequenceNoResponse GetSequenceNo(GetSequenceNo
 $parameters)
   [19]=
   string(95) **UpdateClientMediaLogTimeRespon**se
 UpdateClientMediaLogTime(**UpdateClientMediaLogTime $parameters)
 }

 now this is all great but my question is how do I call each of these
 functions with parameters.
 The call I immediately need to make is to GetSequenceNo() which requires a
 parameter of CIS in my current configuration.
 How do I do this ? Obviously $client-__doRequest is not the way to go.

 --

 Regards,
 Alf Stockton  www.stockton.co.za


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




Re: [PHP] php fopen https error

2013-09-25 Thread Shawn McKenzie
I believe this was a bug, is only a warning that may be suppressed and may
have been fixed in 5.2.0.  Are you aware that PHP is at 5.5.4 and that
5.1.6 is over 7 years old?

-Shawn


On Wed, Sep 25, 2013 at 9:09 AM, Markus Falb markus.f...@fasel.at wrote:

 With RHEL/CentOS 5 php I get an SSL Error
 RHEL/CentOS 5 php is at 5.1.6 with security fixes backported.

 ?php
  $handle = fopen(https://maps.google.com;, r);
  $contents = stream_get_contents($handle);
  fclose($handle);
 ?

 will result in something like

 Warning: stream_get_contents(): SSL: fatal protocol error in bla.php on
 line 3

 Some https pages do not raise this error, e.g. https://www.redhat.com is
 fine
 What is wrong? How to debug? How to resolve? How to mitigate?

 Thanks
 --
 Markus Falb

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




Re: [PHP] php fopen https error

2013-09-25 Thread Shawn McKenzie
Just as I thought:

5.2.0
Fixed bug #39039 SSL: fatal protocol error when fetching HTTPS from servers
running Google web server). (Ilia)


On Wed, Sep 25, 2013 at 10:03 AM, Shawn McKenzie
shawn.mcken...@gmail.comwrote:

 I believe this was a bug, is only a warning that may be suppressed and may
 have been fixed in 5.2.0.  Are you aware that PHP is at 5.5.4 and that
 5.1.6 is over 7 years old?

 -Shawn


 On Wed, Sep 25, 2013 at 9:09 AM, Markus Falb markus.f...@fasel.at wrote:

 With RHEL/CentOS 5 php I get an SSL Error
 RHEL/CentOS 5 php is at 5.1.6 with security fixes backported.

 ?php
  $handle = fopen(https://maps.google.com;, r);
  $contents = stream_get_contents($handle);
  fclose($handle);
 ?

 will result in something like

 Warning: stream_get_contents(): SSL: fatal protocol error in bla.php on
 line 3

 Some https pages do not raise this error, e.g. https://www.redhat.com is
 fine
 What is wrong? How to debug? How to resolve? How to mitigate?

 Thanks
 --
 Markus Falb

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





Re: [PHP] PHP and curl

2013-09-25 Thread Shawn McKenzie
Keep on list.

$result = $client-GetSequenceNo( CIS ); shouldn't be throwing that
error.  Maybe you are trying to do something with $result afterwards?  Try
var_dump($result);


On Wed, Sep 25, 2013 at 10:12 AM, Alf Stockton a...@stockton.co.za wrote:


 On 25/09/13 16:52, Shawn McKenzie wrote:

 $client-GetSequenceNo( $parameters );

 That unfortunately returns

 alf@alf-ThinkPad-T500:~/Development/PHP/DevIt$ php
 php-soap-web-service.php  test.txt
 PHP Catchable fatal error:  Object of class stdClass could not be
 converted to string in
 /home/alf/Development/PHP/DevIt/php-soap-web-service.php on line 7

 No matter if I use
 $result = $client-GetSequenceNo( CIS );
 or
 $result = $client-GetSequenceNo($strTerminalname);




 --

 Regards,
 Alf Stockton  www.stockton.co.za




-- 
--
Thanks!
-Shawn
--


Re: [PHP] php fopen https error

2013-09-25 Thread Shawn McKenzie
I thought I covered that.  The bug was fixed 7 years ago.  Upgrade PHP, I
doubt there is a patch.  I understand that not all coders or distributions
will have the latest version of PHP, but come on, how many thousands of
bugs have been fixed in 7 years?  You're going to run into more.
 Alternatively you could try and suppress it.  From the bug it sounded like
it was only the warning that was the bug, so the code should work.  I can't
test because my PHP on CentOS is only 3 years old (5.3.3).

 $contents = @stream_get_contents($handle);




On Wed, Sep 25, 2013 at 11:20 AM, Markus Falb markus.f...@fasel.at wrote:

 On 25.9.2013 17:12, Shawn McKenzie wrote:
  Just as I thought:
 
  5.2.0
  Fixed bug #39039 SSL: fatal protocol error when fetching HTTPS from
 servers
  running Google web server). (Ilia)

 Thanks, but ...
 I am not sure how what I am supposed to do with this information.

 #39039 says it is a bug and it was fixed.
 How do I proceed to understand this bug?
 Where can I find the appropiate patch?
 Where is this bug discussed?

 I am sorry if I strain it (too much?) but the link to this bug does not
 give a solution to the problem and it does not help to understand the
 problem.

 I understand that somewhere in cvs there is the solution, but I can not
 see an obvious way to get it from the information in #39039
 --
 Markus Falb

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




[PHP] Re: Integer

2013-02-02 Thread Shawn McKenzie
On 02/01/2013 10:40 PM, Ron Piggott wrote:
 In the following the “2.” means a moderator response and “25” is the account 
 # of the moderator.   
 
 ?php
 
 $author = 2.00025
 
 ?
 
 How can I get the 25 by itself?  
 - I want to drop the “2.” and remove all the zero’s
 
 Would it be best to turn this into a STRING?
 
 Any suggestions?
 
 
 Ron Piggott
 
 
 
 www.TheVerseOfTheDay.info 
 

Yeah needs to be a string:

$author = 2.00025;

list($a, $b) = explode('.', $author);

echo (int)$a . ' ' . (int)$b;


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



[PHP] Re: globbed includes?

2012-11-20 Thread Shawn McKenzie
On 11/18/2012 02:29 PM, tamouse mailing lists wrote:
 There are certain times I'd like to include all files in a given
 directory (such as configuration stuff that is split out by type, a la
 apache conf.d). Anyone have something handy that implements that?
 

Just for fun:

array_walk(glob('*.php'), function($arg) { include($arg); });

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



[PHP] Re: What do you call the end-user?

2012-07-24 Thread Shawn McKenzie
On 07/19/2012 12:26 PM, Tedd Sperling wrote:
 Hi gang:
 
 I can't wait for tomorrow -- so here's my off-topic post today.
 
 First question:
 
 What do you call the people who ultimately use your code?

Many times I would call them dumb asses.  Especially many of the users
of free software.  Even with clear detailed user guides and the fact
that it is free, they are indignant about a missing feature or having to
look in the docs for anything.

-- 
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] url string being split

2012-04-27 Thread Shawn McKenzie
On 04/27/2012 10:56 AM, Chris Stinemetz wrote:
 I still haven't been able to find a solution. Is there anyone out
 there that knows how to keep the query string intact?
 
 Thank you,
 
 Chris

urlencode($storerow['store_subject'])

-- 
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] Variable Question

2012-04-19 Thread Shawn McKenzie
On 04/19/2012 09:55 AM, Christoph Boget wrote:
 I am trying to use this while look to assign them to variables:
 $word_1
 $word_2
 $word_3
 ...
 $word_25
 
 This should work for you:
 
 http://us3.php.net/manual/en/function.extract.php
 
 thnx,
 Christoph

Yes and you can use array_map('stripslashes', $row) prior.  However I
would just use the $row array as most people do instead of extracting.

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

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



[PHP] Re: Script failing on extension_dir

2012-04-10 Thread Shawn McKenzie
On 04/09/2012 03:16 PM, George R Smith wrote:
 EXTDIR=`php -i 2 /dev/null | grep -i extension_dir | cut -d  -f3`
 
 Error message follows, what does the no mean ?
 get the directory where PHP extension are stored
 
 You need to create the php extensions directory:
 /usr/lib/php5/20090626+lfs no
 

There is something wrong with the cut where it is getting a 'no' from
the next line.  No time to test fixing that now but the simple fix on
your machine is this:

EXTDIR=/usr/lib/php5/20090626+lfs

-- 
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: Script failing on extension_dir

2012-04-10 Thread Shawn McKenzie
On 04/10/2012 12:25 PM, George R Smith wrote:
 Matijin and Shawn,
 
 I added to /etc/php5/apache2/php.ini the line
 extension_dir = /usr/lib/php5/20090626+lfs
 
 but when I run qm_ext_build I still get
 You need to create the php extensions directory:
 /usr/lib/php5/20090626+lfs no
 
 could the error be in the qm_ext_build script. Here is the
 section of code producing the error.
 
 echo ---
 echo  get the directory where PHP extension are stored
 echo ---
 EXTDIR=`php -i 2 /dev/null | grep -i extension_dir | cut -d  -f3`
 if [ ! -d $EXTDIR ]; then
 echo -n -e \n
 echo 
 echo You need to create the php extensions directory:
 echo $EXTDIR
 echo 
 echo -n -e \n
 exit
 fi
 
 When I run manually I get:
 root@dell350:/usr/qmsys/qmphp# php -i 2 /dev/null | grep -i
 extension_dir |
 cut -d  -f3
 /usr/lib/php5/20090626+lfs
 no
 root@dell350:/usr/qmsys/qmphp#
 
 I am doing this so I can connect the database I use and have only been
 studying PHP
 for 5 days.
 
 I have attached a file with the results of php -I and the build script.
 
 Thanks again
 George
 
 
 
 -Original Message- From: Matijn Woudt
 Sent: Tuesday, April 10, 2012 11:05 AM
 To: Shawn McKenzie
 Cc: George R Smith ; php-general@lists.php.net
 Subject: Re: [PHP] Re: Script failing on extension_dir
 
 On Tue, Apr 10, 2012 at 5:18 PM, Shawn McKenzie nos...@mckenzies.net
 wrote:
 On 04/09/2012 03:16 PM, George R Smith wrote:
 EXTDIR=`php -i 2 /dev/null | grep -i extension_dir | cut -d  -f3`

 Error message follows, what does the no mean ?
 get the directory where PHP extension are stored
 
 You need to create the php extensions directory:
 /usr/lib/php5/20090626+lfs no
 

 There is something wrong with the cut where it is getting a 'no' from
 the next line.  No time to test fixing that now but the simple fix on
 your machine is this:

 EXTDIR=/usr/lib/php5/20090626+lfs

 
 While I agree that it will fix the problem, it does sound suspicious.
 You can check what php -i returns, to check if there is any problem
 with your PHP configuration.

That wasn't my recommendation so I can't comment.

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

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



[PHP] Re: List working?

2012-03-27 Thread Shawn McKenzie
On 03/27/2012 04:23 PM, Jay Blanchard wrote:
 Seems unusual not to have any traffic on it all day long.

i put in my codes but i only get blank page...

-- 
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: List working?

2012-03-27 Thread Shawn McKenzie
On 03/27/2012 04:34 PM, Matijn Woudt wrote:
 On Tue, Mar 27, 2012 at 11:32 PM, Shawn McKenzie nos...@mckenzies.net wrote:
 On 03/27/2012 04:23 PM, Jay Blanchard wrote:
 Seems unusual not to have any traffic on it all day long.

 i put in my codes but i only get blank page...

 
 List seems to be working fine, last message was at 3:11 PM GMT. That's
 about 6 hours ago which doesn't seem unusual..

is not working fine, i put in my php codes and need help with blank screen

-- 
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: List working?

2012-03-27 Thread Shawn McKenzie
On 03/27/2012 08:11 PM, Daniel Fenn wrote:
 It working fine here, just people are busy I suppose.
 

y u no help me  !!  i have white page withg my php codes in my page !
help please !!  asap please  i put codes in my file and is white

 
 On Wed, Mar 28, 2012 at 10:45 AM, Shawn McKenzie nos...@mckenzies.net wrote:
 On 03/27/2012 04:34 PM, Matijn Woudt wrote:
 On Tue, Mar 27, 2012 at 11:32 PM, Shawn McKenzie nos...@mckenzies.net 
 wrote:
 On 03/27/2012 04:23 PM, Jay Blanchard wrote:
 Seems unusual not to have any traffic on it all day long.

 i put in my codes but i only get blank page...


 List seems to be working fine, last message was at 3:11 PM GMT. That's
 about 6 hours ago which doesn't seem unusual..

 is not working fine, i put in my php codes and need help with blank screen

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

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



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

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



[PHP] Re: looking for an array sorting function.. just not sure which one.. and how yet

2012-03-10 Thread Shawn McKenzie
On 03/10/2012 06:42 PM, Govinda wrote:
 Hi Everyone
 
 I am newbie enough with the terminology around PHP arrays that I am slow to 
 wrap my head around what I know is in the docs (what i am reading)... but 
 just can't identify yet.
 
 I think it will be faster if someone can translate for me in terms of my 
 question:
 
 I make an array by building up its members form the results of a db call, 
 like so:
 
 foreach ($query-result() as $row) {
   $arr_cTree[$row-cID] = array($row-cPcID, $row-cL, $row-cName, 
 $row-cSeg, $row-cSort);
 }
 
 I have that array's members' values displaying on an HTML page fine by making 
 recursive function calls to grab the children of each parent member found..  
 but the order those array members are displayed on the page is not what I 
 want (it seems to be displaying according to the order the rows are found in 
 the db).  To remedy, I want to sort on the last value in the array which is 
 the value of each array member.  (If I said that right.)   IOW,  I want to 
 sort my $arr_cTree array by the decimal values stored in $row-cSort 
 ($arr_cTree[[4]), before I then display on the page.
 
 Can someone point me to the array sorting function you think is suited to 
 this job.. and perhaps give me an example in pseudo code if that helps make 
 it more clear in this case.
 
 Thanks!
 -Govinda

The best option is to sort it in the query.  But if for whatever reason
you sort it in the query for use one way and then need it sorted
differently later, then most likely execute another query with the new
sorting.  If having tried that, and that's not what works, then use
array_multisort().  Pay attention to example #3 on php.net as this is
what you want.

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

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



[PHP] Re: looking for an array sorting function.. just not sure which one..and how yet

2012-03-10 Thread Shawn McKenzie
On 03/10/2012 07:01 PM, Shawn McKenzie wrote:
 foreach ($query-result() as $row) {
  $arr_cTree[$row-cID] = array($row-cPcID, $row-cL, $row-cName, 
 $row-cSeg, $row-cSort);
 }

Actually, you may construct your array as follows to make sorting with
ksort():

foreach ($query-result() as $row) {
$arr_cTree[$row-cSort] = array[$row-cID, $row-cPcID, $row-cL,
$row-cName, $row-cSeg, $row-cSort);
}


However you do it, look at constructing your array the way you need it
to easily sort, display etc.

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

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



[PHP] Re: iphone php

2012-03-05 Thread Shawn McKenzie
On 03/05/2012 11:16 AM, Jim Giner wrote:
 An appl that has been working fine for a year now and fine up through last 
 week, suddenly is not working on my iphone.  The only differences between 
 using it on a pc, ipad or iphone are for font sizes and such (handled by JS) 
 so I'm puzzled as to what is going on.  I do the same exact thing on each of 
 these 3 devices and the iphone fails.  The specifics are : I'm entering a 
 date into an input field and php is supposed to retrieve it and display a 
 record that is retrieved using that input.  The iphone for some reason is 
 not getting my input (passed via POST) correctly, yet it's the same script 
 being run for each device.
 
 Trying not to paranoid, but does anyone think that Apple could have done 
 something to my iphone in the last few days? 
 
 

After one of my i[phone software updates, javascript in safari was
turned off.  I know I didn't do it and js had been working great.
Something to check.
-- 
Thanks!
-Shawn
http://www.spidean.com

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



[PHP] Re: Insert new array after specific key in multidimensional array

2012-02-28 Thread Shawn McKenzie
On 02/27/2012 08:12 PM, Micky Hulse wrote:
 Howdy!
 
 Example code:
 
 https://gist.github.com/1928452
 
 What would be the best way to insert $o_insert array into $o array
 after specified key?
 
 I hate to just ask for example code, but I can't seem to find the
 perfect solution. :(
 
 Many thanks in advance for the help!
 
 Cheers,
 Micky


Might be an easier way but this should work.  You can sort the $before =
true out for yourself :-)

function array_insert($array, $key, $insert, $before = FALSE) {
$i = 0;
foreach($array as $k = $v) {
  if($k === $key) {
$p = $i + 1;
break;
  }
  $i++;
}
$array = array_merge(array_slice($array, 0, $p), $insert,
array_slice($array, $p, count($array) - $p));
}

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

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



[PHP] Re: Typecasting question

2012-02-05 Thread Shawn McKenzie
On 02/03/2012 10:11 AM, jas wrote:
 array('private_key_type'   = OPENSSL_KEYTYPE_RSA,
   'encrypt_key_cipher' = OPENSSL_CIPHER_3DES);

Look like ints to me: var_dump():

array(2) {
  [private_key_type]=
  int(0)
  [encrypt_key_cipher]=
  int(4)
}


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

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



[PHP] Re: DOS CLI?

2011-12-02 Thread Shawn McKenzie
On 12/02/2011 03:00 PM, Matt Neimeyer wrote:
 Is there (or is there a way to compile) a DOS CLI version of a fairly
 recent version of PHP? I have not been able to find one using the
 powers of Google.
 
 Not a Windows Command Prompt CLI but an actual CLI version of PHP that
 can be made to run in a real DOS environment?
 
 I'm sure I could find another scripting language for DOS but to
 prototype this project I'd like to not have to learn a new language as
 well. :)
 
 Thanks in advance for ANY suggestions.
 
 Matt

Uh No.  There's not one for the original Berkeley or ATT UNIX,
VMS, CPM, Commodore 64, Mac OS 9 or Amiga either as far as I know.  The
DOS that ran on TRS80, concurrent DOS and Zenith DOS are right as well.

I'm sure that if you submit a feature request they would be all over it.

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

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



[PHP] Re: Sniping on the List

2011-11-15 Thread Shawn McKenzie
On 11/14/2011 11:51 AM, George Langley wrote:
 Am concerned over the number of posts that appear to be from people
 trying to over-inflate their self-importance. If you are the world's
 best coder, then help those of us who aren't. If you happen to know a
 better way to do something that I'm struggling with, then please
 share it. But if you just want to take pot shots at us, then please
 keep your comments to yourself.
 
 To that end, I wish to thank Ashley Sheridan, Daniel P. Brown, Tedd
 Sperling and Tommy Pham, to name but just a few of those who have
 submitted incredibly-helpful posts, that I have kept for reference.
 Your contributions are very much appreciated - thanks.
 
 

I will NOT keep my pot shots to myself.  As the world's BEST coder I
should be afforded, nay, entitled, the luxury to comment however I see
fit!  Especially to sixth century technology idiots such as yourself.
Now, if you have ANY idea who I am or of my importance in this
community, you will craft a carefully worded apology and then cease
posting here for eternity!  By omission, I will assume that I am not
appreciated and take action to see that you are hereby banned from the
Internet. You're messing with the wrong guy!

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

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



[PHP] Re: Converting string to array index

2011-11-06 Thread Shawn McKenzie
On 11/05/2011 09:21 PM, Ethan Rosenberg wrote:
 Dear list -
 
 I have an associative array that will return a string representing an
 array index.  I now need to convert this string into an actual array index.
 
 $test1 = array
 (
 e1 = [4][7],
 e2 = [5][8]
 );
 
 so.. $z = $test1['e1'];
 z has the value of [4][7].  I need to convert this string to an array
 index so I can use it in $results[4][7].
 
 How do I do it?
 
 Thanks.
 
 Ethan
 
 MySQL 5.1  PHP 5.3.3-6  Linux [Debian squeeze(sid)] 
 

Not sure I totally understand, but from my assumption:

foreach($test1 as $k = $v) {
   eval(\$results$v = $k;);
}
print_r($results);

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

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



[PHP] Re: PHP 5.2 and Apache 2.2 are really compatible?

2011-10-19 Thread Shawn McKenzie
On 10/19/2011 10:36 AM, Joseph Adenuga wrote:
 
 
 
 Dear All,
 
 
 I’m using Window XP operating system. I’ve just installed
 PHP 5.2.5 and Apache 2.2.8 over a week now. I’ve checked if Apache 
 installation
 is okay with ‘localhost’ in my Firefox browser and it displays ‘It Works!’ 
 But, my php code ?php  echo h1Hello Web!/h1;
 ? that I saved as ‘first.php’ in the ‘htdocs’ will not display “Hello Web! 
 in my browser. In the ‘Review
 Error Log file’ I found:
 
 
 PHP Warning:  PHP
 Startup: Unable to load dynamic library 'C:\\php\\ext\\php_msql.dll' - The
 specified module could not be found.\r\n in Unknown on line 0
 

There should be a line in your php.ini file similar to this:

extension='C:\\php\\ext\\php_msql.dll'

Comment that out with a semi-colon and restart apache:

;extension='C:\\php\\ext\\php_msql.dll'

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

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



[PHP] Re: files outside of documentRoot

2011-10-08 Thread Shawn McKenzie
On 10/08/2011 03:40 PM, Ricardo Martinez wrote:
 Hi List!
 
 I need to access files outside the DocumentRoot.
 
 I've been looking for info and documentation, and I've read that it can be
 done using symbolic links and another way is by using headers.
 
 I want to know, what do you think, what is the best way, and if anyone knows
 a good doc about of it.
 
 Thanks!!!
 

It depends on what you mean by files.  Are they PHP files that need to
be run, or images, or files that need to be downloaded by the user?

For PHP, you would add the external dir to your include path.

For images you can use a php file as the img src and that file sets the
appropriate headers and uses readfile() to get and echo the image data:
getimage.php?image=someimage.gif

For download files you would do it in the same manner as for images:
download.php?file=somefile.zip


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

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



[PHP] Re: Secure data management

2011-10-04 Thread Shawn McKenzie
On 10/04/2011 02:23 PM, Jim Giner wrote:
 I thought I knew how to do this.
 
 I have a form that collects some data fields.  My script checks if magic 
 quotes are off and (since they are) executes addslashes on each input 
 field.  Then I run a query to INSERT these 'slashed' vars into the database. 
 But when I go to phpadmin on my site the table does not contain any slashes.
 
 Where are they going? 
 
 

The slashes escape data just to tell the database that those
characters are data.  The database doesn't insert the slash, that would
be unwanted.  Not all databases use the slash as an escape character and
for the ones that do you should use the X_real_escape_string(), like
mysql_real_escape_string() instead of addslashes()


-- 
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] book quest

2011-09-28 Thread Shawn McKenzie
On 09/28/2011 06:23 PM, Daniel Brown wrote:
 On Wed, Sep 28, 2011 at 19:13, Andy McKenzie amckenz...@gmail.com wrote:

 I agree with Bastien -- I've had great luck with the PHP books.
 Beginning PHP4 has a permanent place on my shelf, even though PHP4
 is outdated.  Beginning PHP5.3 hasn't quite supplanted it as a
 concept book, but is my go-to for here's a way to solve this
 particular problem using a new version of PHP book.
 
 I'm still waiting for the day when folks on this list get together
 and say, let's put all of our notes together, as beginners and
 intermediates, and put together a book for the newcomers, from the
 newcomers, by the newcomers, who can relate to them without the taint
 of overexperience.
 
 If properly presented, it would not only be easy to shop to
 publishers, but it could also be one of the first truly collaborative
 publications to exist on biological remnants.
 

Why are you waiting for the day Dan?  Just do it!

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

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



[PHP] Re: Question about losing port number

2011-09-26 Thread Shawn McKenzie
On 09/26/2011 05:45 PM, vince chan wrote:
 Hi:
 I have a general question about  PHP:
 So basically I have a link, and I want the href to be absolute., so I
 do 'https://' . $_SERVER['HTTP_HOST'] . '/login' ; this gives me
 https://127.0.0.1/login on my local; however, what i really want is
 https://127.0.0.1:9090/login, it is missing :9090. I also have tried to
 use  $_SERVER['SERVER_PORT'],  but $_SERVER['SERVER_PORT'] doesn't give me
 9090, it gives me 80.
 
 Could anyone help me?
 Thx
 

I the page that you are on is connected via port 80 then
$_SERVER['SERVER_PORT'] will be 80.  If it is connected via 9090 then
$_SERVER['SERVER_PORT'] will be 9090.  If you want it to be different
than how it is currently connected then you will have to hard code the
port number in the href.

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

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



[PHP] Re: How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Shawn McKenzie
On 09/22/2011 10:54 AM, Eric wrote:
 if(preg_match('(.*)^[A-Za-z0-9]+', $_POST['username']) !== 0) {
 echo p style=\color:red;font-weight:bold;margin-left:95px\;
 echo Username must only contain A-Z and 0-9/p;
 include(register.html);
 exit;
 }
 
 I used the code above but I now get this error message
 
 Warning: preg_match() [function.preg-match]: Unknown modifier '^' in 
 C:\Documents and 
 Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\forum\register.php on line 2
 
 I don't like to run php with errors off so I wanna ask how I can fix this.

if(!ctype_alnum($_POST['username'])) {
   // is not alpha numeric
}

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

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



[PHP] Re: PHP 5.4.0beta1 released

2011-09-16 Thread Shawn McKenzie
On 09/15/2011 08:50 PM, d...@php.net wrote:

Thanks X4!


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

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



[PHP] Re: Bug?

2011-09-15 Thread Shawn McKenzie
On 09/15/2011 04:07 PM, Igor Escobar wrote:
 Anyone can explain this?
 
 https://gist.github.com/1220404
 
 Part of the code are in portuguese so...
 iguais = equal
 diferentes = different
 
 Regards,
 Igor Escobar
 *Software Engineer
 *
 + http://blog.igorescobar.com
 + http://www.igorescobar.com
 + @igorescobar http://www.twitter.com/igorescobar
 

1. Obviously because of the issues with floating point precision these
are stored as the same float, a la your next example.

2. Using bc math for binary calculations on string representations of a
number overcomes the problems in 1.

3. This one is peculiar, but it seems that since they are numeric
strings that they are being juggled to float for the comparison since
using == there is no type checking.  Using === yields a different
result, presumably because forcing a type check compares them as
strings.  Use strcmp() to overcome this.

4. Do I need to explain this one?

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

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



[PHP] Re: htmlentities

2011-09-13 Thread Shawn McKenzie
On 09/13/2011 01:38 PM, Ron Piggott wrote:
 
 Is there a way to only change accented characters and not HTML (Example: p 
 /p a href =”” /a )
 
 The syntax
 
 echo htmlentities( stripslashes(mysql_result($whats_new_result,0,message)) 
 ) . \r\n;
 
 is doing everything (as I expect).  I store breaking news within the database 
 as HTML formatted text.  I am trying to see if a work around is available?  
 Do I need to do a variety of search / replace to convert the noted characters 
 above back after htmlentities ?
 
 (I am just starting to get use to accented letters.)
 
 Thanks a lot for your help.
 
 Ron
 
 The Verse of the Day
 “Encouragement from God’s Word”
 http://www.TheVerseOfTheDay.info  
 

If it is meant to be HTML then why run htmlentities(), especially before
storing it in the DB?

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

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



[PHP] Re: Repetitive answers . . .

2011-09-09 Thread Shawn McKenzie
On 09/09/2011 12:04 PM, Joshua Stoutenburg wrote:
 NOTE:  There could be lag caused by network and server technologies.
 Perhaps answers arrive during the time it takes a person to prepare an
 answer.  These are forgivable.

 This is the reason, same as on any other public mailing list.
Better to receive too many responses than not enough.  Besides, more
often than not, it's multiple methods of doing things, not always
identical.  Not only will that never change, but it shouldn't.


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

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



[PHP] Re: Bug #51739 tricky string to float conversion

2011-08-31 Thread Shawn McKenzie
On 08/31/2011 09:03 AM, magic-...@damage.devloop.de wrote:
 Hi,
 I have opend Bug #51739 in 2010. It was closed as bogus before my last
 question was answered. It would be fine to know what you think about
 that bug.
 In short:
 var_dump((float)8315e839da08e2a7afe6dd12ec58245d);
 results in float(INF)
 This is because 8315 is treated as base and
 e839da08e2a7afe6dd12ec58245d is treated as an exponent. My hint that
 e839da08e2a7afe6dd12ec58245d is not a valid exponent was not answered.
 What do you think about?
 cheers
 Daniel

The cast to float is truncating the invalid characters and since your
string contains a float that is INF (8315e839) before the truncation at
the d, then it returns INF.  Makes perfect sense.

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

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



[PHP] Re: Bug #51739 tricky string to float conversion

2011-08-31 Thread Shawn McKenzie
On 08/31/2011 01:48 PM, Shawn McKenzie wrote:
 
 The cast to float is truncating the invalid characters and since your
 string contains a float that is INF (8315e839) before the truncation at
 the d, then it returns INF.  Makes perfect sense.
 

Just FYI...  Don't post your troubles or misunderstandings as bug
reports.  The PHP developers sift through too many reports as it is and
many or maybe the majority are support tickets like yours that are not
bugs.  The people assigned to bugs are not going to explain why your
issue is not a bug in detail.  They are tasked with fixing bugs, and
they have many bug reports (mostly like yours).  The appropriate place
for you to post would be here on this list first.  If the consensus of
the veteran folks on this list is wow, that's a bug or some such, then
we will tell you to post a bug report.

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

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



[PHP] Re: ZCE

2011-08-23 Thread Shawn McKenzie
On 08/23/2011 08:36 AM, Yuri Yarlei wrote:
 Hi,
 
 I like to share with the list, that I passed in the ZCE and now I'm a Zend
 Certified Engineer.
 
 I did a post when I started studying in my blog:
 http://www.yuriyarlei.net/en/zend-php-certification
 

Congratulations!

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

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



[PHP] Re: Unanticipated characters returned from multidimensional array

2011-08-06 Thread Shawn McKenzie
On 08/06/2011 08:09 AM, David Green wrote:
 foreach($tableNews as $headline = $text){
 $new_text = $text['text'];
 echo br;
 echo $new_text;
 foreach ($text as $soucre = $description){
 $new_description = $description['name'];
 echo pre;
 echo $new_description;
 echo /pre;
 }
 
 }

I haven't look through it long enough to find out about the characters,
but try this:

foreach($tableNews as $headline = $text){
echo br;
echo $text['text'];
echo pre;
echo $text['user']['name'];
echo /pre;
}


-- 
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] Complex (or not so) array data form submission?

2011-08-04 Thread Shawn McKenzie
On 08/04/2011 01:56 PM, Andrew Ballard wrote:
 On Thu, Aug 4, 2011 at 2:04 PM, Jamie Krasnoo jkras...@gmail.com wrote:
 Thanks. I think what I got hung up on was that I was trying this:

 name=addresses[][id]
 name=addresses[][address1]
 name=addresses[][address2]
 name=addresses[][city]
 name=addresses[][state]
 name=addresses[][zip]

 Which wouldn't have given the end result I sought, I don't think. Clear case
 of not seeing the forest for the trees.

 Jamie
 
 It probably would have worked just fine. Not specifying the numeric
 index means that PHP will depend on the order that the browser sends
 the values, but they are generally sent in the order they appear on
 the form. If the numeric index is important, it's better to provide it
 explicitly.
 
 Andrew

What Jamie posted is equivalent to this:

name=addresses[0][id]
name=addresses[1][address1]
name=addresses[2][address2]
name=addresses[3][city]
name=addresses[4][state]
name=addresses[5][zip]

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

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



[PHP] Re: $_POST value disappearing?

2011-08-02 Thread Shawn McKenzie
On 08/02/2011 10:04 AM, Donovan Brooke wrote:
 Hello!,
 
 I must not be understanding something as I would expect 'f_file'
 to show up in the print_r below.:
 
 ---form--
 form action=index.php method=post enctype=multipart/form-data
   input type=hidden name=f_ap value=upload /
   input type=hidden name=f_action value=doit /
   input type=file  name=f_file /
   input type=submit value=Upload /
 /form
 ---endform--
 
 --index.php--
 ?php print_r($_POST); ?
 --/index.php--
 
 
 
 
 The result I get is:
 
 Array
 (
 [f_ap] = upload
 [f_action] = doit
 )
 ---
 
 Can someone enlighten me?
 
 Thanks,
 Donovan
 
 

The manual is great!  $_FILES

http://www.php.net/manual/en/features.file-upload.post-method.php

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

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



[PHP] Re: I can't execute pf commands

2011-07-28 Thread Shawn McKenzie
On 07/28/2011 11:09 AM, Bulent Malik wrote:
 Hi
 
 I use php5.3 on freebsd
 
 I also use pf ( packet filter) on it.
 
 I need to execute pfctl in php script.  But I couldn't execute . I don't get
 any errors about that.
 
 Shell commands is allowed in  php.ini My 
 
 My script is below,
 
 
  shell_exec('pfctl -s nat');
 
 exec('pfctl -s nat');
 
 
 If I execute another command like this ; it works
 
 shell_exec('ls -l /var/tmp') ;
 
 What can the problem be ? 
 
 

pfctl probably requires root privileges, so you can either set the suid
on it or I would set it up in sudoers to allow the apache user to
execute it without a password.

-- 
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] I can't execute pf commands

2011-07-28 Thread Shawn McKenzie
On 07/28/2011 01:22 PM, Arthur Moczulski wrote:
 Answer to your problem is in your pop Apache module configuration. I would
 suggest to look how different your cli php.ini file is in comparison to your
 Apache php module php.ini file

No

 Also I would not follow the suggestion of adding Apache user to sudoers.
 It's quite high risk move in security-wise

Good luck getting it to work another way.


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

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



[PHP] Re: pathinfo function

2011-07-26 Thread Shawn McKenzie
On 07/26/2011 05:47 PM, Tim Streater wrote:
 Is it to be expected that, if a file has no extension, and I do this:
 
$info = pathinfo ($myfile);
 
 that I will get an error if I try to reference $info[extension] ??
 
 --
 Cheers  --  Tim

Just like any other array you'll get a notice:

Notice: Undefined index: extension

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

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



[PHP] Re: PHP frameworks

2011-07-21 Thread Shawn McKenzie
On 07/21/2011 03:59 PM, Chris Stinemetz wrote:
 Hello all,
 
 I am thinking about venturing into PHP frameworks, but I would like to
 get advice on what the correct selection would be for someone that is
 about intermediate in PHP knowledge.
 
 Thank you,

So, with your post you will probably get one or more replies suggesting
every one of the popular frameworks and then several that suggest some
lesser known ones.

I think Zend looks great, but for many people (including me) it is
overly complex and cumbersome.  It is a very professional and
standardised class library, but has no glue to put it all together for
you. Also, it takes OOP to the extreme (for PHP anyway).  Everything has
abstract classes, interfaces and the like.

CI is good from a lightweight, gives you something to build on perspective.

I however prefer CakePHP.  Its been around for a while, it can
automatically build an app from just a well designed database and
doesn't require configuration files in XML, YAML or what have you.  The
documentation is OK and could be much better.

It really depends on what you want out of the framework.  I would
suggest going through the CakePHP and CI tutorials and seeing which one
seems like a good fit for you.


-- 
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: PHP frameworks

2011-07-21 Thread Shawn McKenzie
On 07/21/2011 07:44 PM, Micky Hulse wrote:
 On Thu, Jul 21, 2011 at 5:33 PM, Micky Hulse rgmi...@gmail.com wrote:
 Your app models?
 
 More specifically, your app model data. :)

A la CakePHP.  Will automagically build controllers and views for the
admin of your tables/models if you wish.

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

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



[PHP] Re: IF stream lining

2011-07-14 Thread Shawn McKenzie
On 07/13/2011 11:20 PM, Ron Piggott wrote:
 
 Is there a way to stream line this:
 
 if ( ( $val  with ) AND ( $val  from ) ) {
 
 Ron
 
 The Verse of the Day
 “Encouragement from God’s Word”
 http://www.TheVerseOfTheDay.info  
 

Depends on what you mean by streamlined.  If it were longer, this might
be useful:

if(!in_array($val, array('with','from','to','against','mom','dad')) {

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

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



[PHP] Re: Variable scope

2011-07-14 Thread Shawn McKenzie
On 07/14/2011 03:54 PM, Karl DeSaulniers wrote:
 Can anyone explain this to me.

I can't read through all that crap, but I notice multiple times that you
use undefined variables, due to typo or just not remembering what they are.

You pass in $subjField but later try and use $subjectField.  You pass in
$e_cc but try and use $_email_cc, etc, etc, etc...

Develop with:

error_reporting(E_ALL);
ini_set('display_errors', '1');

This will tell you about all of those undefined variables.

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

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



[PHP] Re: str_replace around a character??

2011-07-14 Thread Shawn McKenzie
On 07/13/2011 04:03 PM, Karl DeSaulniers wrote:
 
 Thanks Shawn,
 I had actually found the same thing myself..
 
 $subCc = array_map('trim',explode(,,$subCc));
 
 But I could not find my post last night to make a new comment about it.
 Thank you for yours though.. I did not think of the implode part.
 
 Best,
 
 Karl DeSaulniers
 Design Drumm
 http://designdrumm.com
 

You probably want the array_filter() in there also, because commas at
the beginning or end or other issues can leave you with empty array
elements that will still be imploded resulting in just a comma.

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

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



[PHP] Re: str_replace around a character??

2011-07-13 Thread Shawn McKenzie
On 07/13/2011 02:54 AM, Karl DeSaulniers wrote:
 Hello All,
 I am needing some assistance. I am trying to add some Cc and Bcc to a
 mail script I have.
 On the form I have instructions for each to be separated by a comma + a
 space.
 In an all perfect world each user would do this perfectly. ...but since
 were working with something different,
 how can I check for this? and catch any that dont do this perfectly?
 
 Is there a reg exp that covers this? I have seen many, but some make the
 head cramp. Mi mui novicio.
 To wrap it up, I am basically trying to do this...
 
 $cc = ema...@domain.com ,ema...@doamin.com,ema...@domain.com ,
 ema...@domain.com, 
 
 to be
 
 $cc = ema...@domain.com, ema...@doamin.com, ema...@domain.com,
 ema...@domain.com
 
 Any pointers would be much appreciated.
 TIA
 Best Regards,
 
 Karl DeSaulniers
 Design Drumm
 http://designdrumm.com
 
 
$cc = implode(', ', array_filter(array_map('trim', explode(',', $cc;

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

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



[PHP] Re: Installing PHP

2011-07-04 Thread Shawn McKenzie
On 07/04/2011 07:39 AM, Jim Giner wrote:
 Hi all,
 (Hopefully I posted this in a place that can/will help me)
 
 I got curious about running php / apache on my own laptop in order to help
 my devl process, instead of writing, uploading and testing on my site.
 
 Found a nice pair of docs from thesitewizard.com that appeared to be
 pretty well-written instructions on installing each of these systems.  btw-
 I'm running XpSp2.  Chose the Apache 2.0 and PHP 5.2 (thread-safe?) per the
 recommendations.
 
 Went thru all instructions step-by-step, testing all the way.  Apache
 works - PHP doesn't.  When I bring up IE and type in localhost I get the
 default apache page as I was told I should see.  When I type
 localhost/test.php I get a windows dialog asking what program should run
 the php script.
 
 In debugging I went to a cmd windows and ran c:\php\php-cgi test.php and
 got the expected result from my script - so PHP works.
 
 End result - they each work separately, but php is not working under apache.
 
 As part of the docs instructions I added the following code to the apache
 conf file:
 
 1 - I chose the configure apache to run php as an apache module.
 2 - added LoadModule php5_module c:/php/php5apache2.dll as last one of
 those lines
 3 - added AddType application/x-httpd-php .php as the last of those lines
 4 - added PHPIniDir c:/php as the last line of the conf file.
 
 Upon adding these lines apache will no longer restart.  In fact adding any
 ONE of these lines breaks Apache.
 
 Ideas welcome.
 
 And for those who still love the USofA, Happy Independence Day!
 

You may need to add c:\php\ to the Windows path so that the Apache mod
can find other files it may need. If you have mysql or other extensions
enabled in php.ini, then they may be looking for another dll that is
located in the php dir.

And of course, Happy Independence Day!

-- 
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: Php filter validate url

2011-06-27 Thread Shawn McKenzie
On 06/27/2011 10:01 AM, Plamen Ivanov wrote:
 On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie nos...@mckenzies.net wrote:

 On 06/26/2011 12:31 PM, Adam Tong wrote:
 Hi,

 I wanted tu use php filters for validation to avoid regular expresions.
 Is it possible that FILTER_VALIDATE_URL only checks if the string has
 http:// and do not check for the format domain.something?
 
 $url = 'http://wwwtestcom';
 $url = filter_var($url,FILTER_VALIDATE_URL);
 echo $url;
 -

 Or I am doing something wrong

 Thank you

 Unless I'm totally misunderstanding what you want (validate that a
 string starts with http://) try:

 if(strpos($url, 'http://') === 0) {
   //starts with http://
 } esle {
   // does not start with http://
 }

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

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

 
 Another possible solution could be:
 
 $ary = explode('://', $url);
 if (1 = count($ary)) {
 echo 'No schema specified!';
 } else {
 // Schema specified.
 // $ary[0] is the protocol
 $allowed = array('http', 'https');
 if (FALSE == in_array($ary[0], $allowed) {
 // Protocol not valid!
 exit(1); // or return FALSE; whatever...
 }
 // $ary[1] is the uri, validate with filter_var().
 }
 
 Hope this helps.

May make more sense to use parse_url() than explode.

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

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



[PHP] Re: Php filter validate url

2011-06-26 Thread Shawn McKenzie
On 06/26/2011 12:31 PM, Adam Tong wrote:
 Hi,
 
 I wanted tu use php filters for validation to avoid regular expresions.
 Is it possible that FILTER_VALIDATE_URL only checks if the string has
 http:// and do not check for the format domain.something?
 
 $url = 'http://wwwtestcom';
 $url = filter_var($url,FILTER_VALIDATE_URL);
 echo $url;
 -
 
 Or I am doing something wrong
 
 Thank you

No, because http:// is not a URL, it's a scheme or protocol.

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

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



[PHP] Re: Php filter validate url

2011-06-26 Thread Shawn McKenzie
On 06/26/2011 12:31 PM, Adam Tong wrote:
 Hi,
 
 I wanted tu use php filters for validation to avoid regular expresions.
 Is it possible that FILTER_VALIDATE_URL only checks if the string has
 http:// and do not check for the format domain.something?
 
 $url = 'http://wwwtestcom';
 $url = filter_var($url,FILTER_VALIDATE_URL);
 echo $url;
 -
 
 Or I am doing something wrong
 
 Thank you

Unless I'm totally misunderstanding what you want (validate that a
string starts with http://) try:

if(strpos($url, 'http://') === 0) {
   //starts with http://
} esle {
   // does not start with http://
}

-- 
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: Php filter validate url

2011-06-26 Thread Shawn McKenzie
On 06/26/2011 04:50 PM, Fatih P. wrote:
 Guys, when you reply a mail, You should write your reply on the top of it,
 not at the bottom of it.
 makes it easier to follow.
 

Ready flame-throwers!

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

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



[PHP] Re: this newsgroup and OE

2011-06-22 Thread Shawn McKenzie
On 06/22/2011 09:45 AM, Jim Giner wrote:
 Perhaps someone can tell me the secret to getting problem-free access to the 
 php newsgroups using OE.  I have two other newsgroup servers configured in 
 OE which do not give me any difficulties at all.  My setup for news.php.net 
 however gives me nothing but problems.  Inability to connect to messages, 
 long delays during normal polling for new items that hangs up my normal mail 
 traffic, etc.  Right now, OE indicates two new messages in the php.general 
 list, but I cannot download them at this time because OE says it cannot 
 connect (oops - just went to get the text of the message and now OE has been 
 able to connect).
 
 Some of the details of my config:
 server name: php.new.net
 port #: 119
 timeouts: 30 secs.
 
 nothing else in particular set up - same as my other working newsgroup 
 accounts.
 
 Thanks in advance. 
 
 

No secret.  This has been happening to me every day for years using
Thunderbird.  It's a news server issue that has never been corrected.

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

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



[PHP] Re: newbie date time question

2011-06-22 Thread Shawn McKenzie
On 06/22/2011 09:05 AM, David Nicholls wrote:
 I'm trying to convert a date and time string using strtotime()
 
 The date and time strings are the first entry in each line in a csv file
 in the form:
 
 22/06/2011 9:47:20 PM, data1, data2,...
 
 I've been trying to use the following approach, without success:
 
 function read_data($filename)
 {
 $f = fopen($filename, 'r');
 while ($d = fgetcsv($f)) {
 
 $format = 'd/m/Y h:i:s';
 $dt = DateTime::createFromFormat($format, $d[0]);
 
 $data[] = array(strtotime($dt), $d[1]); //convert date/time
 }
 fclose($f);
 return $data;
 }
 
 Obviously I'm not getting the $format line right, as the resulting $dt
 values are empty.  (I have previously used this reading process
 successfully with better behaved date and time strings).
 
 Advice appreciated.
 
 DN

I'm late to the party, but strtotime works great, though you need to
give it what it expects:

$ts = strtotime(str_replace('/', '-', $date));

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

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



[PHP] Re: newbie date time question

2011-06-22 Thread Shawn McKenzie
On 06/22/2011 06:54 PM, David Nicholls wrote:
 I'm late to the party, but strtotime works great, though you need to
 give it what it expects:

 $ts = strtotime(str_replace('/', '-', $date));

 
 Thanks, Shawn, that's a bit more elegant!  I'll give it a go. I didn't
 know how to do the str_relace bit.  Thanks

The deal is that if you use the / then strtotime interprets it as m/d/y
and if you use - it interprets it as d-m-y.

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

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



[PHP] Re: mysqlnd and LOAD DATA INFILE

2011-06-20 Thread Shawn McKenzie
On 06/20/2011 07:51 AM, Marten Lehmann wrote:
 isn't working any longer

What does that mean?  It generates an error?  It executes without error
but the data isn't loaded?  Try a test on the command line and see what
you get.

-- 
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: mysqlnd and LOAD DATA INFILE

2011-06-20 Thread Shawn McKenzie
On 06/20/2011 10:53 AM, Marten Lehmann wrote:
 Hello,
 
 What does that mean?  It generates an error?  It executes without error
 but the data isn't loaded?  Try a test on the command line and see what
 you get.
 
 when calling mysql_error() the message The used
 command is not allowed with this MySQL version is returned.
 
 I thought maybe knows between this and mysqlnd? Because recompiling PHP
 with --with-mysql=mysqlnd is the only difference to the previous PHP
 build, where LOAD DATA INFILE worked.
 
 Kind regards
 Marten

This is a PHP list, but most likely run: mysql_fix_privilege_tables and
then restart mysql.

-- 
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] Submit Using An Image Form Processing

2011-06-19 Thread Shawn McKenzie
On 06/19/2011 07:26 AM, tedd wrote:
 At 6:34 PM -0500 6/18/11, Shawn McKenzie wrote:

 Get method is for retrieval only.  It is not for anything that has a
 consequence (insert, update, delete, send email, etc.).  Use only post
 for those.

 -- 
 Thanks!
 -Shawn
 
 
 Why?
 
 Cheers,
 
 tedd
 

The convention has been established that the GET and HEAD methods SHOULD
NOT have the significance of taking an action other than retrieval.
These methods ought to be considered safe. This allows user agents to
represent other methods, such as POST, PUT and DELETE, in a special way,
so that the user is made aware of the fact that a possibly unsafe action
is being requested.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

-- 
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] Submit Using An Image Form Processing

2011-06-18 Thread Shawn McKenzie
On 06/18/2011 11:06 AM, Jason Pruim wrote:
 
 On Jun 18, 2011, at 11:54 AM, Ron Piggott ron.pigg...@actsministries.org 
 wrote:
 
 INPUT TYPE=image 
 SRC=http://www.theverseoftheday.info/store-images/trash_can.png; WIDTH=20 
  HEIGHT=20 style=float: right;boarder: 0; alt=Remove Product From 
 Shopping Cart name=remove_product value=1 /
 
 I would wrap the image in a link like so:
 a href=mypage.php?id={$autoincrementnum}img src=blah/a
 
 And then have a get look for that variable:
 
 $id=$_get[id];
 
 If (isset($id)) {
 
 //delete code here
 }
 
 Check all that before you run it I'm writing from my smart phone and it's 
 all untested. Hopefully it gives you a start though. 
 
 Jason Pruim 

Get method is for retrieval only.  It is not for anything that has a
consequence (insert, update, delete, send email, etc.).  Use only post
for those.

-- 
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] date.timezone set and still getting strict warnings.

2011-06-14 Thread Shawn McKenzie
On 06/14/2011 09:35 AM, Tamara Temple wrote:
 
 On Jun 13, 2011, at 4:17 PM, Daniel Brown wrote:
 
 On Mon, Jun 13, 2011 at 16:25, Tamara Temple tamouse.li...@gmail.com
 wrote:
 I have date.timezone set, as shown in the phpinfo() output:

 portfolio:Downloads tamara$ php -r 'phpinfo();' | grep 'timezone'
 Default timezone = America/Chicago
 date.timezone = 'America/Chicago' = 'America/Chicago'

That's the CLI version of PHP

 Yet, when I call a function like strtotime(), i still get the Strict
 warning
 about not having date.timezone set. (Yes, I have restarted the server,
 twice, and the correct value shows up if I invoke phpinfo() via the
 server.)

 and you're referencing the web version here.

 Any clues?

Check the web version of PHP's phpinfo() output and see if it and
 the CLI are using the same php.ini file.  My guess is that they're
 not, and - while the CLI one is set with the timezone - its web
 counterpart is missing the flag.
 
 Ok, first off, are you telling me the CLI and the Web versions reference
 different php.ini files? I thought they both used /etc/php.ini...
 
 Secondly, I *did* check the output of phpinfo() from the web with the
 exact same results.
 
 Now, the problem is...
 
I surrounded the date.timezone setting with single quotes.
 
 So, removing the quotes got me what I needed.
 

Glad you got it fixed.  Many distros do it differently.  Windows
normally has one php.ini, Ubuntu and derivatives have 2.  Other will
vary.  Here's mine:

/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

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

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



[PHP] Re: Extracting data from exec() call

2011-06-14 Thread Shawn McKenzie
On 06/14/2011 12:35 PM, Ashley M. Kirchner wrote:
 
 I'm trying to extract data coming from an exec() call.  The exec()
 call is performing an ncdump on a netCDF file:
 
 ?php
   $filename = mlab.20110101.cdf;
   exec(/usr/bin/ncdump -l 2048 -v wmax .$filename, $output);
   echo ---\n;
   print_r($output);
   echo ---\n;
 ?
 
 This is all fine, however the data comes in with extra information I
 don't need, and the data I do need is in a long string format:
 
 Array
 (
 [0] = netcdf mlab.20110101 {
 [1] = dimensions:
 [2] =  time = UNLIMITED ; // (288 currently)
 [3] = variables:
 [4] =  int base_time ;
 [5] =  int samp_secs ;
 [6] =  float lat ;
 [7] =  float lon ;
 [8] =  float alt ;
 [9] =  int station ;
 [10] = float time_offset(time) ;
 [11] = float tdry(time) ;
 [12] = float rh(time) ;
 [13] = float pres(time) ;
 [14] = float cpres0(time) ;
 [15] = float dp(time) ;
 [16] = float wdir(time) ;
 [17] = float wspd(time) ;
 [18] = float wmax(time) ;
 [19] = float wsdev(time) ;
 [20] = float wchill(time) ;
 [21] = float raina(time) ;
 [22] = float raina24(time) ;
 [23] = float bat(time) ;
 [24] = data:
 [25] =
 [26] =  wmax = 5, 5, 5, 5.4, 5.7, 5.1, 7.1, 6.1, 4.4, 9.5,
 13.5, 14.4, 11.1, 9.6, 10.5, 10.6, 11.1, 10, 15.3, 17.2, 16.9, 16, 13.9,
 16.7, 15.3, 18.3, 17.2, 16.3, 15.9, 18.9, 17.7, 19.7, 19.7, 16.6, 16.4,
 16, 14.6, 14.9, 14, 16.7, 18.3, 16.2, 18.4, 15.4, 15.3, 13.3, 14.8,
 15.6, 15.1, 14.7, 13.8, 14.2, 18, 16.7, 16.6, 15.6, 15.8, 17.6, 17.4,
 20.3, 17.4, 21.3, 18.7, 16.7, 15.4, 17.5, 17.3, 17.7, 20.4, 17.5, 16.8,
 18.1, 15.9, 17.8, 17.3, 13.9, 16.2, 17.4, 19.8, 17.5, 19, 20, 20.3,
 20.4, 20.8, 21.6, 26.4, 23.1, 21.3, 19.9, 20.1, 21.1, 22.1, 22.5, 21.2,
 20.2, 22.2, 21.6, 19.6, 21.1, 21.7, 21, 20.8, 23.7, 26.6, 21.2, 23.8,
 23.3, 23.5, 23.9, 21.4, 22.1, 23.5, 22.8, 23, 21.8, 22.2, 25.6, 21.9,
 22.8, 26.2, 24.2, 23.6, 25.5, 26.8, 25.6, 27.4, 24.5, 23.5, 22.1, 23.1,
 25.5, 22.5, 22.5, 23.8, 21.8, 22.6, 23.5, 24, 23, 22.3, 21.6, 23.6,
 20.5, 21, 19.4, 23.6, 19.2, 18, 19.2, 20.5, 19.3, 19.1, 20.4, 18, 17.8,
 18.4, 19.4, 21, 18.3, 20.4, 21.2, 22.1, 20.1, 17.3, 17.2, 17.6, 17.2,
 19.9, 21, 20.6, 21.5, 23.8, 25, 24, 23.9, 23.5, 27.7, 21.1, 20.8, 20.1,
 18.6, 21, 18.7, 19.9, 16.4, 16.3, 17.3, 11.8, 11.4, 15.2, 12.4, 14.2,
 16.3, 21.6, 25, 19, 7.7, 9.7, 15.7, 7, 11.1, 10.3, 11.2, 14.8, 11.7,
 5.5, 5.5, 5.5, 6.9, 7.6, 6.5, 6.4, 6.7, 6.7, 4.9, 5.1, 4.7, 5.7, 5.5,
 9.2, 6.2, 7.1, 7.7, 6.5, 5.5, 6, 6.4, 7, 6.2, 6.7, 4.7, 3.8, 9.2, 8.1,
 7.6, 6.8, 6.3, 7.1, 10.5, 8, 9.9, 10.2, 12, 9.4, 14, 18, 11.9, 17.7,
 20.9, 18.8, 17.4, 13.5, 13.8, 12.6, 5.5, 6.1, 6.6, 6.3, 6.3, 5.1, 7.7,
 5.8, 5.4, 4.9, 4.5, 4.9, 4.7, 5, 4.8, 4.5, 5.6, 5.9, 4.6, 5.7, 7.2, 6.1,
 6.4, 5.4, 6.1, 5.6, 5.9, 6.4, 9.5, 11.2, 15.8, 15, 13.6 ;
 [27] = }
 )
 
 ncdump doesn't provide an option to suppress the header information,
 and as you can hopefully tell, the data I'm looking for is in one long
 string at key position 26.
 
 How can I extract what I need from that (wmax) and have it as an
 array: wmax = array(5, 5, ...)
 
 This is only one variable.  I will be pulling more variables out,
 and they all come out the same way as above, as strings.  The headers
 might change, so I can't simply say ignore the first 0-25 keys and
 expect what I need to be at position 26.  I need a reliable way of
 detecting where the data section starts.  And I need to convert the
 strings into arrays for each data set.
 
 Suggestions?

Assuming that it is always the second to the last item, then:

$wmax = explode(', ', $output[count($output)-1]);
array_shift($wmax);
print_r($wmax);

--or to search for wmax =

if($array = preg_grep('/^ wmax = $/', $output)) {
   $wmax = explode(', ', $array[0]);
}
array_shift($wmax);
print_r($wmax);

May need some more error checking.

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

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



[PHP] Re: Extracting data from exec() call

2011-06-14 Thread Shawn McKenzie
On 06/14/2011 01:03 PM, Shawn McKenzie wrote:
 $wmax = explode(', ', $output[count($output)-1]);

Should be -2 :(

$wmax = explode(', ', $output[count($output)-2]);


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

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



[PHP] Re: Extracting data from exec() call

2011-06-14 Thread Shawn McKenzie
On 06/14/2011 01:30 PM, Ashley M. Kirchner wrote:
 if ($array = preg_grep('/^ wmax = /', $output)) {
 $array = array_values($array);
 $wmax = explode(', ', $array[0]);
   }

Sorry, didn't have a way to test when I posted.  So you've posted two
different expected outputs and I misread the first.  You want a string
of only the coma separated numbers?  If so:

if ($array = preg_grep('/^ wmax = /', $output)) {
   $wmax = array_shift($array);
}

If you want to get rid of the wmax = or add the { } or whatever use
str_replace() and/or concat then on.

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

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



[PHP] Re: Fuzzy Array Search

2011-06-07 Thread Shawn McKenzie
On 06/07/2011 12:45 PM, Floyd Resler wrote:
 What would be the easiest way to do a fuzzy array search?  Can I do this 
 without having to step through the array?
 
 Thanks!
 Floyd
 

I use preg_grep()

-- 
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: Fuzzy Array Search

2011-06-07 Thread Shawn McKenzie
On 06/07/2011 03:57 PM, Floyd Resler wrote:
 
 On Jun 7, 2011, at 4:42 PM, Alex Nikitin wrote:
 
 If you don't need the location, you can implode the array and use preg
 match, quickly testing it, that gives you about 4.5 times performance
 increase, but it wont give you the location, only if a certain value exists
 within the array... You can kind of do some really clever math to get your
 search parameters from there, which would be feasible on really large data
 sets, but if you want location, you will have to iterate at some point...

 (sorry i keep on hitting reply instead of reply to all)

 --
 The trouble with programmers is that you can never tell what a programmer is
 doing until it’s too late.  ~Seymour Cray



 On Tue, Jun 7, 2011 at 2:57 PM, Shawn McKenzie nos...@mckenzies.net wrote:

 On 06/07/2011 12:45 PM, Floyd Resler wrote:
 What would be the easiest way to do a fuzzy array search?  Can I do this
 without having to step through the array?

 Thanks!
 Floyd


 I use preg_grep()

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

 
 I actually do need the location since I need to get the resulting match.  I 
 went ahead and tried to iterate the array and it was MUCH faster than I 
 expected it to be!  Of course, considering the machine I'm running this on is 
 a monster (2.66 GHz 8 cores, 24GB of RAM) it shouldn't have surprised me!
 
 Thanks!
 Floyd
 

If you are using a straight equality comparison then the loop would be
faster (but then array search would probably be better), however if you
need to use a preg_match() in the loop (fuzzy search), then
preg_grep() will be much faster than the loop.

LOOP WITH PREG_MATCH: 10
 0.435957 seconds
PREG_GREP: 10
 0.085604 seconds

LOOP WITH IF ==: 10
 0.044594 seconds
PREG_GREP: 10
 0.091519 seconds

-- 
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: Fuzzy Array Search

2011-06-07 Thread Shawn McKenzie


On 06/07/2011 04:28 PM, Floyd Resler wrote:

 Shawn,
   I'm terrible with regular expressions.  Could you give me an example?

 Thanks!
 Floyd



Depends.  Could be as simple as this to return an array of all
occurrences of $needle in any of the $haystack_array values:

$haystack_array = array('something is here', 'nothing matches here',
'there will be a somethingsomething match here');
$needle = 'something';
$matches_array = preg_grep(/$needle/, $haystack_array);

Depends on where you are getting the search criteria and how you want it
to match in the array.  BTW...  If this is originally in a database then
you can do it there with the LIKE operator and % wildcard.

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



Re: [PHP] Re: Fuzzy Array Search

2011-06-07 Thread Shawn McKenzie


On 06/07/2011 04:35 PM, Alex Nikitin wrote:
 Shawn, == is not good for string comparison, its a bad habit that one
 should get out of, use ===, its much safer .
Yes, except that I was comparing a string to an array of integers :)

 Also try the same algorithm on 10 arrays of some number of values
 10-1000 perhaps, that would give you better performance statistics :)

LOOP WITH PREG MATCH:  650.627260 seconds
PREG_GREP:  123.110386 seconds

This was with 100,000 arrays each with 1,000 values.  Of course the loop
iterates through the entire loop which is needed to find all matches. 
If only one match is needed then you can just break out of the loop to
save time.  If we assume that half of the matches will be in the lower
500 and half in the upper then we can half the time for the loop but it
is still 325 seconds.

Thanks!
-Shawn

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



[PHP] Re: A Review Request

2011-05-19 Thread Shawn McKenzie
On 05/18/2011 02:22 PM, tedd wrote:
 Hi gang:
 
 I am considering providing PHP code to the general public via my website
 
 This is my first attempt:
 
 http://sperling.com/php/authorization/
 
 What do you people think?
 
 Cheers,
 
 tedd
 

I have to agree about the braces, but at our ages that's not going to
change :-)

My suggestion would be to use syntax highlighting.  Geshi is a very good
one that supports lots of languages/syntaxes, but PHP's highlight_file()
and highlight_string() do an adequate job.

As the site grows and you have PHP, HTML, CSS, JS and maybe INI files
and SQL, then Geshi would handle all of these.


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

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



[PHP] Re: Storing indefinite arrays in database

2011-05-11 Thread Shawn McKenzie
On 05/10/2011 03:16 PM, Benedikt Voigt wrote:
 Hi,
 I'am very new to PHP, so please any comment is welcome.
 
 I want to write a function in PHP, which takes X arguments and outputs a
 value.
 The functioning of this function should be stored in a db (mydb? or
 better alternatives?)
 The function would look up the result in the db based on the X arguments.
 
 But how can I store X arguments and the corresponding output value?
 If I limit the X arguments to a specific number like N=10, then I could
 create N=10 +1 columns in a table.
 But how should I do it if I don't want to limit myself to a fix number?
 
 Thanks for any comment!
 Ben

Two ways that come to mind:

1. If you don't need to search, join, etc. on any of the arguments in
the DB (*and never will need to*), then serialize the array and store it
in one column and the result in another.

2. Use two tables:

results
id  result
1   50
2   99

arguments
id  results_id  argument
1   1   800
2   1   999
3   1   3.14

Then you just join results.id on arguments.results_id in your query.

If you actually need to store the argument name then just add another
column called variable and change the argument column's name to value.


id  results_id  variable  value


-- 
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: Storing indefinite arrays in database

2011-05-11 Thread Shawn McKenzie


On 05/11/2011 03:15 PM, Benedikt Voigt wrote:
 Thanks Shawn,

 yes, your second idea works for me. The first one not, as I need to
 search and join on it.
 To continue your second idea with your example:

 Arguments:
 idresults_idvariablevalue
 111800
 212999
 3133.14

 Results:
 idresult
 150
 299

 The Arguments and Results table would be filled dynamically by user
 content.
 In order to run a function, I have to do N times a join, whereas N is
 the number of arguments:

 select result
 from Results join Arguments as A1 join Arguments as A2 join Arguments
 as A3
 on Results.id=A1.results_id and
 on Results.id=A2.results_id and
 on Results.id=A3.results_id and
 where
 A1.variable=1 and A1.value=800 and
 A2.variable=2 and A2.value=999 and
 A3.variable=3 and A3.value=3.14 and
 A1.results_id=Results.results_id and
 A2.results_id=Results.results_id and
 A3.results_id=Results.results_id

 Theoretically this works, but how good will be the performance if
 there are Thousands of entries?
 Anyway, I will try out.
 Thanks again,
 Ben




 Shawn McKenzie schrieb:

 On 05/10/2011 03:16 PM, Benedikt Voigt wrote:
   
 Hi,
 I'am very new to PHP, so please any comment is welcome.

 I want to write a function in PHP, which takes X arguments and
 outputs a
 value.
 The functioning of this function should be stored in a db (mydb? or
 better alternatives?)
 The function would look up the result in the db based on the X
 arguments.

 But how can I store X arguments and the corresponding output value?
 If I limit the X arguments to a specific number like N=10, then I could
 create N=10 +1 columns in a table.
 But how should I do it if I don't want to limit myself to a fix number?

 Thanks for any comment!
 Ben
  
 Two ways that come to mind:

 1. If you don't need to search, join, etc. on any of the arguments in
 the DB (*and never will need to*), then serialize the array and store it
 in one column and the result in another.

 2. Use two tables:

 results
 id  result
 1   50
 2   99

 arguments
 id  results_id  argument
 1   1   800
 2   1   999
 3   1   3.14

 Then you just join results.id on arguments.results_id in your query.

 If you actually need to store the argument name then just add another
 column called variable and change the argument column's name to value.


 id  results_id  variable  value





I just read your post quickly so maybe I'm off, but your query makes no
sense.

What is known (to use in the where clause to limit by) and what do you
want to retrieve?

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



[PHP] Re: files outside of the web tree

2011-04-27 Thread Shawn McKenzie
On 04/27/2011 12:08 PM, Jim Giner wrote:
 I have managed to build include files and store them above my public folder 
 and the called pages manage to find them from the public folder and properly 
 include them.  My problem is with the html src= attribute.  I have uploaded 
 photos to  be included in my web pages and I didn't want them in the web 
 tree so I moved them above it also. I use php to get the root folder's name 
 and then I add ../photos/ to the filename's path, but now my tags can't 
 find them.  Can I not do this? 
 
 

One way to do this is to have a PHP file as the image source.  The PHP
file would grab the image outside of the web root and echo it along with
the proper headers.  This is the same principle as storing the binary
image data in a database.

img src=photo.php?name=mydog.png


//photo.php
$file = '/path/to/photos/' . basename($_GET['name']);
$type = mime_content_type($file);
header('Content-type: $type');
readfile($file);

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

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



[PHP] Re: JavaScript Injection ???

2011-04-18 Thread Shawn McKenzie
On 04/18/2011 12:06 PM, tedd wrote:
 Hi gang:
 
 Quite some time ago I had a demo that showed Javascript injection. It
 was where a user could type in:
 
 script alert(Evil Code);/script
 
 and a JavaScript alert would be shown.
 
 But now my demo no longer works. So, what happened? Was there a php
 update that prohibited that sort of behavior or did hosts start setting
 something to OFF, or what?
 
 If you know, please explain.
 
 Thanks,
 
 tedd

Most likely like magic_quotes_gpc.  Suhosin-Patch may protect against
this as well (can't remember).

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

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



[PHP] Re: How to write a PHP coding to list out all files and directories aslinks to them?

2011-04-16 Thread Shawn McKenzie
On 04/14/2011 06:16 PM, Mikhail S wrote:
 How to write a PHP coding to list out all files and directories as links to
 them?
 
 This is somewhat similar to some index pages. When new file or folder is
 added to the directory, HTML page should display the newly created
 file/folder together with previous ones after it is being refreshed. (prefer
 in alphabatical order)
 
 How to achieve this sort of functionality in PHP? Please provide sample
 coding as well. (and any references)
 
 Thanks.
 
 --
 Mike
 http://jp.shopsloop.com/
 

I prefer glob().  Give it a shot and ask for help on code that you have
tried.


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

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



[PHP] Re: Ranges for case statement and a WTF moment.

2011-04-06 Thread Shawn McKenzie
On 04/05/2011 10:28 AM, Richard Quadling wrote:
 Hi.
 
 I just wanted to quickly see if PHP supported ranges in its
 switch/case statement (http://en.wikipedia.org/wiki/Ellipsis)
 
 ?php
 $s = intval(date('s'));
 switch($s)
   {
   case 0...9   : echo 'Between 0 and 9'; break;
   case 10...19 : echo 'Between 10 and 19'; break;
   case 20...29 : echo 'Between 20 and 29'; break;
   case 30...39 : echo 'Between 30 and 39'; break;
   case 40...49 : echo 'Between 40 and 49'; break;
   case 50...59 : echo 'Between 50 and 59'; break;
   default  : echo 'Unknown : ', $s;
   }
 ?
 
 Completely unexpectedly, the above code runs but produces the wrong output.

FYI. My first inclination would have been:

switch(true) {
   case in_array($s, range(0, 9)): echo 0 - 9; break;
}

But it's messy.

-- 
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] problem with if and exact match

2011-03-15 Thread Shawn McKenzie
On 03/15/2011 07:30 AM, Steve Staples wrote:
 
 Wouldn't this be better to use, as it is meant to search for the string
 inside the string?  (use use regex)
 
 if(stristr($name, 'Jackson'))
 {
   echo String is in String;
 }
 else
 {
   echo Failed;
 }
 
 http://ca.php.net/manual/en/function.strstr.php  (case sensative)
 http://ca.php.net/manual/en/function.stristr.php (case insensative)
 
 Steve.
 


From your link:

Note:

If you only want to determine if a particular needle occurs within
haystack, use the faster and less memory intensive function strpos()
instead.


-- 
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] $_POST variable

2011-03-12 Thread Shawn McKenzie
On 03/12/2011 10:37 AM, tedd wrote:
 At 9:28 PM +0200 3/11/11, Danny wrote:
 Hi guys,

 I have a form that has a long list of radio-bottons inside of it. The
 radio-buttons are dynamically created via php and MySQL.

 Here is an example of one of the radio buttons:

 input type=radio name=?php print (radio_.$result_from_mysql) ;
 ? value=0
 input type=radio name=?php print (radio_.$result_from_mysql) ;
 ? value=1

 Now, when I submit this form to another page for processing, how would
 I catch
 the above radio-button's $_POST name since I do not know the name,
 only that it
 starts with radio_ ?

 Thank You

 Danny
 
 
 Danny:
 
 Replace ?php print (radio_.$result_from_mysql) ; ? with an option[]
 array.
 
 Realize that the name of the radio input stays the same -- it is the
 value that changes.
 
 Here's a demo:
 
 http://php1.net/b/form-radio1/
 
 Don't make it more complicated than it needs be.
 
 Cheers,
 
 tedd
 

My point exactly!  So long as the name of the name[] part is the same
they will be treated as the same group of radio buttons.

So here is the long and short; if the name is the same and you specify
an index then names with the same index will be grouped together:
name[1] and name[1] are the same but different group from name[2].  If
you don't specify an index, but the name is the same, then they are
grouped together:  name[], name[].

By grouped together I mean that only one of the group can be selected
and therefore successful on submit.

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

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



[PHP] Re: $_POST variable

2011-03-11 Thread Shawn McKenzie
On 03/11/2011 01:28 PM, Danny wrote:
 Hi guys,
 
 I have a form that has a long list of radio-bottons inside of it. The
 radio-buttons are dynamically created via php and MySQL.
 
 Here is an example of one of the radio buttons:
 
 input type=radio name=?php print (radio_.$result_from_mysql) ; ? 
 value=0
 input type=radio name=?php print (radio_.$result_from_mysql) ; ? 
 value=1
 
 Now, when I submit this form to another page for processing, how would I 
 catch
 the above radio-button's $_POST name since I do not know the name, only that 
 it
 starts with radio_ ?
 
 Thank You
 
 Danny

The most common and flexible way to do this sort of thing is to use
arrays instead:

input type=radio name=radio[?php echo $result_from_mysql; ?]
value=0
input type=radio name=radio[?php echo $result_from_mysql; ?]
value=1


Then:

foreach($_POST['radio'] as $key = $value) {
   echo radio for $key is $value;
}
-- 
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: $_POST variable

2011-03-11 Thread Shawn McKenzie
On 03/11/2011 02:33 PM, Jim Lucas wrote:
 On 3/11/2011 12:03 PM, Shawn McKenzie wrote:
 On 03/11/2011 01:28 PM, Danny wrote:
 Hi guys,

 I have a form that has a long list of radio-bottons inside of it. The
 radio-buttons are dynamically created via php and MySQL.

 Here is an example of one of the radio buttons:

 input type=radio name=?php print (radio_.$result_from_mysql) ; ? 
 value=0
 input type=radio name=?php print (radio_.$result_from_mysql) ; ? 
 value=1

 Now, when I submit this form to another page for processing, how would I 
 catch
 the above radio-button's $_POST name since I do not know the name, only 
 that it
 starts with radio_ ?

 Thank You

 Danny

 The most common and flexible way to do this sort of thing is to use
 arrays instead:

 input type=radio name=radio[?php echo $result_from_mysql; ?]
 value=0
 input type=radio name=radio[?php echo $result_from_mysql; ?]
 value=1


 Then:

 foreach($_POST['radio'] as $key = $value) {
echo radio for $key is $value;
 }
 
 Your example would be good if the OP wanted checkbox'es.  But with radio
 buttons, the whole point (most of the time) is to have the form only allow you
 to have one of the radio input fields selected at any given time.  How you
 showed it, it would not see the uniqueness of the radio button names, and
 therefor allow more than one of the radio input fields to be selected at a 
 time.

One radio button of the same name selected at a time yes.  From the OP's
code of two radios, one with value 0 and one with value 1, I assumed
these were to be a pair with the same name with only one able to be
successful.  This extends to arrays as well:

input type=radio name=radio[] value=0
input type=radio name=radio[] value=1

input type=radio name=radio[555] value=0
input type=radio name=radio[555] value=1

This works as expected, the same as the code I posted.

-- 
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: Regex for extracting quoted strings

2011-03-07 Thread Shawn McKenzie
On 03/05/2011 04:38 PM, Mark Kelly wrote:
 Hi.
 
 Thanks for all the replies.
 
 On Saturday 05 Mar 2011 at 22:11 Simon J Welsh wrote:
 
 On 6/03/2011, at 11:08 AM, Shawn McKenzie wrote:
 $regex = '/([^]+)/';
 
 Shawn, this regex gets me two copies of each string - one with and one 
 without 
 the double quotes - as did the one Nathan posted earlier.
  
 Also, you'll want preg_match_all rather than preg_match.
 
 Yeah, I realised that quite early on in my messing about.
 
 What I have ended up with is:
 
 $regex = '/.*?/';
 $found = preg_match_all($regex, $sentence, $phrases);
 
 This still leaves the quotes in the phrases, but at least I only get one copy 
 of each phrase. I'm just trimming the quotes afterwards.
 
 Thanks for all the advice.
 
 Mark

$sentence = 'Dave said This is it. Nope, that is the wrong colour
she replied.';

$regex = '/([^]+)/';
preg_match_all($regex, $sentence, $phrases);

print_r($phrases[1]);

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

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



[PHP] Re: Regex for extracting quoted strings

2011-03-05 Thread Shawn McKenzie
On 03/05/2011 09:26 AM, Mark Kelly wrote:
 Hi.
 
 I'm hoping someone can help me extract text between double quotes from a 
 string.
 
 $regex = 'some magic';
 $r = preg_match($regex, $sentence, $phrases);
 
 So, if 
 
 $sentence = 'Dave said This is it. Nope, that is the wrong colour she 
 replied.';
 
 I want $phrases to contain 'This is it' and 'Nope, that is the wrong colour'.
 
 Can anyone help?
 
 Cheers,
 
 Mark

$regex = '/([^]+)/';

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

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



[PHP] Re: String Encodings - loose guidelines

2011-01-26 Thread Shawn McKenzie
On 01/25/2011 02:36 PM, Donovan Brooke wrote:
 Hello,
 
 I don't yet have a complete understanding of string encodings for the
 various environments they may need to pass through or be in. I have
 found bits and pieces within Larry's book, the online docs, and by
 googling... and
 my app seems to be working fine, but I don't yet feel confident on best
 practices. So, I thought I'd see if I could spark some feedback to  the
 following:
 
 1.) Saving strings to a database

Just use the proper escaping and save what is received:
example:  mysql_real_escape_string() or a addcslashes() for DBs without
a comparable function or preg_replace() for those that escape differently:

If you definitely don't want certain things then strip them:
striptags()

If you may need it then leave it.

 
 2.) print/echo'ing string fields from a database.
 a. Allowing HTML?
 b. Not allowing HTML?

Depends on whether you want to render HTML.  If so, and you can trust it
(you or a trusted source entered it) then do nothing.  Otherwise if you
want to show the HTML as source tags then:
htmlentities()

If you don't want it then strip it before insert or when displaying,
your call:
striptags()

 
 3.) print/echo'ing string fields into form textareas.

The textarea prevents HTML inside from being rendered and the form
submit should automatically URL encode the data in the textarea so I
don't see the need to do anything.

 
 4.) Simply encoding strings to send over a GET request.

Encode the values that you intend to pass:
urlencode()

 
 5.) Simply displaying strings from the $_REQUEST array.

If you want to maybe show some HTML as source tags then:
htmlentities()

If you don't want HTML then strip it when displaying:
striptags()

 
 6.) string encoding for redirects
 

Same as #4.

BTW, these are very nice for working with data:

filter_var()
filter_var_array()
filter_input()
filter_input_array()


-- 
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] Installing PEAR

2011-01-25 Thread Shawn McKenzie
On 01/25/2011 11:25 AM, Nilesh Govindarajan wrote:
 On 01/25/2011 10:32 PM, Ethan Rosenberg wrote:
 Dear List --

 How do install PEAR on Linux?  I installed lynx and as root, I ran the
 command lynx -source http://pear.php.net/go-pear | php.  It seemed to
 install, but the command pear did not work.  From the root directory I
 ran the command find . -name pear.  There was no file found.  I also
 tried Pear, with the same results.

 Help and advice, please.

 Ethan

 MySQL 5.1  PHP 5.3.3-6  Linux [Debian (sid)]


 
 If you are using php from the repositories, there must be a pear package
 as well in the repos. Check for them.
 

Yes, I'm on Ubuntu and just used 'apt-get install php-pear'.

-- 
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: array to var - with different name

2011-01-21 Thread Shawn McKenzie


On 01/20/2011 05:26 PM, Tommy Pham wrote:
 On Thu, Jan 20, 2011 at 2:49 PM, Shawn McKenzie nos...@mckenzies.net wrote:
 On 01/20/2011 04:28 PM, Donovan Brooke wrote:
 Hello again!

 I'm trying to find a good way to convert array key/value's to
 variable name values... but with the caveat of the name being
 slightly different than the original key
 (to fit my naming conventions).

 first, I (tediously) did this:

 ---
 if (isset($_GET['f_action'])) {
   $t_action = $_GET['f_action'];
 }

 if (isset($_POST['f_action'])) {
   $t_action = $_POST['f_action'];
 }

 if (isset($_GET['f_ap'])) {
   $t_ap = $_GET['f_ap'];
 }

 if (isset($_POST['f_ap'])) {
   $t_ap = $_POST['f_ap'];
 }
 ---

 Instead, I wanted to find *all* incoming f_ keys in the POST/GET
 array, and convert them to a variable name consisting of t_ in one
 statement.

 I then did this test and it appears to work (sorry for email line breaks):

 -
 $a_formvars = array('f_1' = '1','f_2' = '2','f_3' = '3','f_4' =
 '4','f_5' = '5','f_6' = '6',);

 $t_string = ;
 foreach ($a_formvars as $key = $value) {
   if (substr($key,0,2) == 'f_') {
 $t_string = $t_string . t_ . substr($key,2) . =$value;
 parse_str($t_string);
   }
 }
 -

 I figure I can adapt the above by doing something like:

 $a_formvars = array_merge($_POST,$_GET);

 However, I thought I'd check with you all to see if there is something
 I'm missing. I don't speak PHP that well and there may be an easier way.

 Thanks,
 Donovan


 I'm sure you have a good reason for doing this?  It is needlessly adding
 complexity, but here is a one liner (not tested):

 extract(array_combine(str_replace('f_', 't_', array_keys($_POST)),
 array_values($_POST)));

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

 That will fail if by chance that he has a form name set to
 a_f_something or similar along the line. Or a possible attack that
 comes in the form submission.

 Regards,
 Tommy

Yes, so maybe a simple preg_replace():

extract(array_combine(preg_replace('/^f_/', 't_', array_keys($_POST)),
array_values($_POST)));

You could also just replace with '' and then use the extract prefix of 't'.

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



[PHP] Re: News Server Time Outs

2011-01-20 Thread Shawn McKenzie
On 01/19/2011 10:09 AM, Al wrote:
 The newsgroup server seems to have a repeated-visit throttle, or whatever.
 
 For the last two weeks at least, I can only open 2 or 3 messages and
 them I get repeated time-outs.  It acts like the DoS or flood prevention
 is kidding in to aggressively.
 
 Al..

Yesterday I couldn't connect at all, all day.  Today it seems to be
working OK.

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

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



[PHP] Re: array to var - with different name

2011-01-20 Thread Shawn McKenzie
On 01/20/2011 04:28 PM, Donovan Brooke wrote:
 Hello again!
 
 I'm trying to find a good way to convert array key/value's to
 variable name values... but with the caveat of the name being
 slightly different than the original key
 (to fit my naming conventions).
 
 first, I (tediously) did this:
 
 ---
 if (isset($_GET['f_action'])) {
   $t_action = $_GET['f_action'];
 }
 
 if (isset($_POST['f_action'])) {
   $t_action = $_POST['f_action'];
 }
 
 if (isset($_GET['f_ap'])) {
   $t_ap = $_GET['f_ap'];
 }
 
 if (isset($_POST['f_ap'])) {
   $t_ap = $_POST['f_ap'];
 }
 ---
 
 Instead, I wanted to find *all* incoming f_ keys in the POST/GET
 array, and convert them to a variable name consisting of t_ in one
 statement.
 
 I then did this test and it appears to work (sorry for email line breaks):
 
 -
 $a_formvars = array('f_1' = '1','f_2' = '2','f_3' = '3','f_4' =
 '4','f_5' = '5','f_6' = '6',);
 
 $t_string = ;
 foreach ($a_formvars as $key = $value) {
   if (substr($key,0,2) == 'f_') {
 $t_string = $t_string . t_ . substr($key,2) . =$value;
 parse_str($t_string);
   }
 }
 -
 
 I figure I can adapt the above by doing something like:
 
 $a_formvars = array_merge($_POST,$_GET);
 
 However, I thought I'd check with you all to see if there is something
 I'm missing. I don't speak PHP that well and there may be an easier way.
 
 Thanks,
 Donovan
 
 

I'm sure you have a good reason for doing this?  It is needlessly adding
complexity, but here is a one liner (not tested):

extract(array_combine(str_replace('f_', 't_', array_keys($_POST)),
array_values($_POST)));

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

2010-10-14 Thread Shawn McKenzie
On 10/14/2010 09:22 AM, Mattias Thorslund wrote:
 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
 

echo serialize(327.03 * 100);

-- 
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] Question about news.php.net

2010-09-13 Thread Shawn McKenzie
On 09/13/2010 06:51 PM, MikeB wrote:
 Daniel Brown wrote:

  I don't believe that we've been having any issues with the server,
 no.  Are you using NNTP to connect?
 
 yes, NNTP.
 
 You may want to consider using
 the HTTP-based RSS and/or RDF feeds if it continues to be an issue.
 
 If this persists, I'll look into the alternatives you suggest, but
 that's another hill to climb when all I'm trying to do is learn PHP and
 web and mySQL and javascrip and...   :)  (not complaining, just that
 right now I've got a lot on my plate and the scope of new things just
 seem to keep expanding faster than I can get a handle on it).
 
 In addition, if you continue to have problems, file a bug report at
 http://bugs.php.net/ and we'll look into it further.

 Thanks, I did that. In the process I found a 2005 bug report that said
 nntp was deliberately throttled to discourage its use... :)
 
 As part of the bug report I included a link to an image of my nntp config.
 
 

I have had this problem every day for years.  I can read a message and
then click another one and it times out.  It does this for hours at a
time.  Also, many times when sending a reply it times out.  Just learned
to live with it because I don't want mailing list mails either.


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

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



[PHP] Re: How to handle a submitted form with no changes -- best practices sought

2010-09-12 Thread Shawn McKenzie
On 09/12/2010 02:38 AM, Tamara Temple wrote:
 
 On Sep 11, 2010, at 10:46 PM, Shawn McKenzie wrote:
 It could however be a problem if there is a BOT or something that
 continually submits to your page.  In that case (and in general) I would
 recommend using a form token that helps guard against this.
 
 I've seen this on some sites, but I'm unclear how to implement this.
 How is this generally done?
 
 Thanks,
 Tamara
 

You generate a token before you display the form, something like:
$token = md5(uniqid(rand(), TRUE));  Then stick this in a session var
and add it as a hidden input on your form.

Then on the receiving page check that the session token matches the
posted token.

viraj's idea sounds cool for your particular problem as well.

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

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



[PHP] Re: How to handle a submitted form with no changes -- best practices sought

2010-09-11 Thread Shawn McKenzie
On 09/11/2010 11:52 AM, Tamara Temple wrote:
 I have a general question and am looking for best practices.
 
 Suppose I present a user with a form for editing an entry in a table,
 i.e., the form has filled in values from the existing table entry.
 
 Now, suppose they click on 'submit' without making any changes in the
 form. (Perhaps, say, rather than clicking 'Cancel' or 'Return to Main'
 or some other option which would get them out of that screen without
 submitting the form).
 
 Is it worth the overhead of passing along the previous values in the
 table in hidden fields so that fields can be checked to see if they've
 been updated or not after the submit? Or is it worth reloading the old
 values from the table to check against the newly submitted form? Or is
 all that overhead not worth the time because an update that overwrites
 existing values with the same values is not that onerous?
 
 (Is that question clear enough?)

I would just submit the query.  Unless you have hundreds or thousands of
users per second that load the form and submit the form with no changes,
then there really is no problem.

It could however be a problem if there is a BOT or something that
continually submits to your page.  In that case (and in general) I would
recommend using a form token that helps guard against this.


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

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



[PHP] Re: php cli question

2010-09-11 Thread Shawn McKenzie
On 09/10/2010 11:13 AM, J Ravi Menon wrote:
 Hi,
 
 I have some basic questions on running php  (5.2.x series on Linux
 2.6) as a standalone daemon using posix methods (fork() etc..):
 
 #!/usr/bin/php
 ?php
 
 require_once ('someclass.php');
 
 // do some initializations
 .
 
 // main 'forever' loop - the '$shutdown'  will
 // be set to true via a signal handler
 
 while(!$shutdown)
 {
   $a = new SomeClass();
 
   $a-doSomething()
 
 }
 
 // shutdown logic.
 
 The 'someclass.php' in turn will include other files (via require_once).
 
 The above file will be executed directly from the shell. The main loop
 could be listening to new requests via sockets etc..
 
 Few questions:
 
 1) Does opcode cache really matter in such cli-based daemons? As
 'SomeClass' is instantiated at every loop, I am assuming it is only
 compiled once as it has already been 'seen'.
 I am not very clear on how apc (or eaccelerator) works in such cases.
 
 
 2) What about garbage collection? In a standard apache-mod-php setup,
 we rely on the end of a request-cycle to free up resources - close
 file descriptiors, free up memory etc..
 I am assuming in the aforesaid standalone daemon case, we would
 have to do this manually?  In the loop above, would it be better to
 'unset($a)' explicitly at the end of it before
 it goes to the next iteration?
 
 Note: I have written pre-forker deamons in php directly and
 successfully deployed them in the past, but never looked at in depth
 to understand all the nuances. Anecdotally, I have
 done 'unset()' at some critical places were large arrays were used,
 and I think it helped. AFAIK, unlike Java, there is no 'garbage
 collector' thread that does all the magic?
 
 Thanks,
 Ravi

If I have time when you reply I'll answer the questions, but I must ask:
 Is this purely academic?  Why is this a concern?  Have you encountered
issues?  If so, what?

-- 
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] Encoding Ampersands

2010-07-29 Thread Shawn McKenzie
On 07/28/2010 11:29 PM, Rick Dwyer wrote:
 So htmlentities() will work for Green, Red  Blue?
 
 Will it work for htm?color=bluenumber=2letter=?
 
 --Rick

For ampersands yes, for other things no.  Use the correct tool for the
job.  To output HTML use htmlentities().  To pass in the URL use
urlencode().

At some point you're going to have a value that contains a = or ? or
something else that you need to pass in the URL.  That's what
urlencode() is for.

 
 
 On Jul 29, 2010, at 12:23 AM, Josh Kehn wrote:
 
 Rick-

 Probably would use htmlentities() instead. You could also do 
 str_replace(, amp;);

 Regards,

 -Josh

 On Jul 29, 2010, at 12:18 AM, Rick Dwyer wrote:

 Hello List.

 I have variables displaying content from mysql fields.  The contents 
 contains  like Dogs  Cats... so naturally the W3C validator chokes on 
 them.

 Is there a way to encode so they display properly on the page but the 
 validator is OK with them?


 Is the answer as simple as:

 urlencode($myvar)

 Thanks,
 --Rick


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


 


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

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



[PHP] Re: PHP database interface layer

2010-07-22 Thread Shawn McKenzie
On 07/22/2010 08:35 AM, Marc Guay wrote:
 Hi everyone,
 
 I've built a fairly large normalized database schema for a project.
 This is fun for me as I like thinking about how everything is
 interconnected.  Foreign keys are all set up, many-to-many tables are
 go, etc, and so on.   But now it's time to create an interface between
 that database and the website using PHP.  I've searched the web and
 this is obviously a very common problem with many solutions, but I
 can't help but feel that all of the logic I've built into the database
 is worth nothing once I start coding.  I found this
 article/presentation that essentially sums up my frustration:
 http://mag-sol.com/talks/lpm/2006/orm/.  Up until now I've been
 working on smaller projects with only a few tables that don't really
 relate to each other, and have found this tool
 (http://www.ricocheting.com/code/php/mysql-database-class-wrapper)
 very handy for the reasons he explains, but I'm looking for something
 a little different.  I've looked at RedBean and it seems pretty handy,
 but it also requires me to redefine all of the foreign keys I've
 already defined, which is annoying.  Any hope of something like
 
 // Get company where name='Widgets Inc.' or id=1 or
 $company = $db-get_company(name='Widgets Inc.');
 
 // Get all clients joined to the company
 $clients = $company-get_clients();
 
 // Get all projects joined to the client
 $projects = $clients-get_projects();
 
 ?

You may not want a full fledged framework, but I would recommend
CakePHP.  Now they have naming conventions for tables/columns, that if
you follow, makes it sooo easy, but if you already have your schema
built it can use that just as easily.

Just run the cake script, enter db details, it will enumerate tables and
columns and ask which are related by which keys and even let you enter
validation rules etc.  It then builds a skeleton app with all the models
for your schema and will even generate test.

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

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



[PHP] Re: Weird behavior of exec()

2010-07-15 Thread Shawn McKenzie
On 07/15/2010 10:51 AM, Leonardo wrote:
 Hi everybody. I need to use exec() to run a background php script, but
 it's not working properly. Take a look at this sample:
 
 a.php
?
 
echo ' File A (1) ';
 
exec('php b.php  output.txt ');
 
echo ' File A (2) ';
 
?
 
 b.php
?
 
echo 'File B';
 
?
 

Try not use the short open tag.  Use ?php

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

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



[PHP] Re: Weird behavior of exec()

2010-07-15 Thread Shawn McKenzie
On 07/15/2010 04:40 PM, Leonardo wrote:
 
 Bad habit. I know.

Did it fix it?

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

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



[PHP] Re: validating form input

2010-07-09 Thread Shawn McKenzie
On 07/08/2010 02:38 PM, David Mehler wrote:
 Hello,
 Got a form that takes in data to enter in to a database. I want to
 make it as secure and as invulnerable to sql injection and other
 attacks as possible. I'm wondering if mysqli_real_escape_string or
 stripslashes should be used or if the former does the latter. For
 example, I have a name variable:
 

In general this is fine:

 $name = mysqli_real_escape_string($DatabaseLink, trim($_POST['name']));
 
 or should I do:

You need to do something like this only if magic_quotes are enabled on
your PHP installation, except you would stripslashes first:

if(get_magic_quotes_gpc()) {
   $_POST['name'] = stripslashes($_POST['name']);
}
$name = mysqli_real_escape_string($DatabaseLink, trim($_POST['name']));

 
 $name = stripslashes(mysqli_real_escape_string($dbc, trim($_POST['name'])));
 
 Thanks.
 Dave.


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

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



[PHP] Re: Multiple Access Question

2010-07-07 Thread Shawn McKenzie
On 07/07/2010 11:59 AM, tedd wrote:
 Hi gang:
 
 I have *my way* of handling this problem, but I would like to hear how
 you guys do it.
 
 Here's the problem -- let's say you have a database containing names and
 addresses and you want approved users to be able to access the data.
 As such, a user must login before accessing an editing script that would
 allow them to review and edit the data -- nothing complicated about that.
 
 However, let's say you have more than one user accessing the editing
 script at the same time and you want to make sure that any changes made
 to the database are done in the most efficient manner possible.
 
 For example, if two users access the database at the same time and are
 editing different records, then there's no real problem. When each user
 finishes editing they simply click submit and their changes are recorded
 in the database. However, if two (or more) users want to access the same
 record, then how do you handle that?
 
 Cheers,
 
 tedd

I would load up the current db values at the beginning of the edit form
and store them in the session.  Then on the processing page look them up
again and see if they match the session values.  If not, then load the
edit form again with a message that says the record has recently been
updated by someone else.

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

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



[PHP] Re: Another parse problem

2010-06-16 Thread Shawn McKenzie
On 06/14/2010 08:14 AM, tedd wrote:
 Hi gang:
 
 Considering all the recent parsing, here's another problem to consider
 -- given any text, parse the domain-names out of it.
 
 You may limit the parsing to the most popular TDL's, such as .com, .net,
 and .org, but the finished result should be an array containing all the
 domain-names found in a text file.
 
 Cheers,
 
 tedd


Not extensively tested:

$domains = array();

if(preg_match_all('/[A-Za-z0-9][-A-Za-z0-9\.]*?\.(com|net|org)/i',
$text, $matches)) {
$domains = array_unique($matches[0]);
}

-- 
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] Cookie access with CLI

2010-06-13 Thread Shawn McKenzie
On 06/13/2010 09:58 AM, David Česal wrote:
 Hello,
 
 I'm trying to access (from CLI) some website, where login is required.
 Please, is it possible to set/save some cookies first (login session
 information) and then access the website as logged user? All through CLI.
 
  
 
 Thank you very much for any information.
 
  
 
 David Cesal
 
 

I'm almost positive you can do this with cURL and it should be fairly
simple.  Check it out.

http://php.net/manual/en/book.curl.php

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

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



  1   2   3   4   5   6   7   8   9   10   >