Re: [PHP] Can't connect to MySQL via PHP

2013-01-13 Thread Rick Dwyer
Hi Jim, and all the rest.

Thanks for the help.  What was throwing me was the EXACT same creds were being 
used to connect via Navicat… but not when using PHP.
Could not figure it out.  So I zapped gremlins in BBEdit on my test file.. 
which had literally no more lines than what I posted to this list… not 
expecting it to work since the code was so simple and I saw nothing out of 
place…but it did, I connected after that.  So some character had to gotten 
placed into the file when moving from one hosting provider to another.

Thanks to all who offered help regarding the connection issue.


 --Rick


On Jan 13, 2013, at 12:12 PM, Jim Giner jim.gi...@albanyhandball.com wrote:

 Regardless of the choice of interface to mysql, regardless of the completely 
 harmless but educational tips from Ash, and very deliberately ignoring the 
 un-helpful and extraneous comments of others,
 I'm wondering how the OP is doing with getting his mysql access working.  
 Haven't heard from him lately.
 
 Rick?
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


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



[PHP] Can't connect to MySQL via PHP

2013-01-12 Thread Rick Dwyer
Hello all.

I used the code below successfully to connect to a MySQL db on one hosting 
provider.  I've moved the code to a new hosting provider with new values and it 
returns:

Access denied for user 'user'@'db.hostprovider.net' (using password: YES)

Even though I can copy and paste these three values (host, user and pass) and 
paste into Navicat to make a connection.  So the credentials are correct, but 
they are not authenticating when used in PHP.  I've tried making host 
localhost and 127.0.0.1… both with the same result.

Can someone tell me what I am doing wrong here?

Appreciate it.

Thanks,
--Rick



$db_name = mydb;
$vc_host= db.hostprovider.net; 
$vc_user= user;
$vc_pass= pass;
 
$connection = @mysql_connect($vc_host, $vc_user, $vc_pass);
$db = mysql_select_db($db_name, $connection);

echo mysql_error();




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



Re: [PHP] Can't connect to MySQL via PHP

2013-01-12 Thread Rick Dwyer

On Jan 12, 2013, at 3:56 PM, admin ad...@buskirkgraphics.com wrote:

 
 
 -Original Message-
 From: Rick Dwyer [mailto:rpdw...@earthlink.net]
 Sent: Saturday, January 12, 2013 8:26 AM
 To: php-general@lists.php.net
 Subject: [PHP] Can't connect to MySQL via PHP
 
 Hello all.
 
 I used the code below successfully to connect to a MySQL db on one
 hosting provider.  I've moved the code to a new hosting provider with
 new values and it returns:
 
 Access denied for user 'user'@'db.hostprovider.net' (using password:
 YES)
 
 Even though I can copy and paste these three values (host, user and
 pass) and paste into Navicat to make a connection.  So the credentials
 are correct, but they are not authenticating when used in PHP.  I've
 tried making host localhost and 127.0.0.1. both with the same
 result.
 
 Can someone tell me what I am doing wrong here?
 
 Appreciate it.
 
 Thanks,
 --Rick
 
 
 
 $db_name = mydb;
 $vc_host= db.hostprovider.net;
 $vc_user= user;
 $vc_pass= pass;
 
 $connection = @mysql_connect($vc_host, $vc_user, $vc_pass); $db =
 mysql_select_db($db_name, $connection);
 
 echo mysql_error();
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
 http://www.php.net/unsub.php
 
 
 Try this for me
 
 ---
 
 $db = mysql_connect($vc_host, $vc_user, $vc_pass); 
 mysql_select_db($db_name, $db);
 
 if (!$db) {
   die('Could not connect: ' . mysql_error());
 }
 echo 'Connected successfully';
 mysql_close($db);


Could not connect: Access denied for user 'user'@'localhost' (using password: 
YES)

Using mysqli_ returns the same error message as well.


--Rick


 
 --Rick




Re: [PHP] Pear Mail - Trap for errors?

2012-11-15 Thread Rick Dwyer
On Nov 14, 2012, at 10:48 PM, tamouse mailing lists tamouse.li...@gmail.com 
wrote:

 On Wed, Nov 14, 2012 at 7:19 PM, Rick Dwyer rpdw...@earthlink.net wrote:
 Hello all.
 
 I have some Pear Mail code composing an email and sending it to an external 
 smtp server for sending.
 
 The issue is determining whether that external server actually accepted the 
 mail or not.  In the IF(PEAR… code below, it will return success even if I 
 leave the $to value empty.  However, if I remove the smtp username or 
 password, it will return an error indicating it could not reach the remote 
 server.  So the Pear::IsError function seems to only reflect if the intended 
 server was accessible… and not if the intended server accepted the outgoing 
 email for delivery.
 
 Anyone have experience with the scenario below… specifically with 
 determining if the smtp server accepted the mail for delivery?
 
 Thanks for any info.
 
 --Rick
 
 require_once Mail.php;
 
 $from = f...@address.com;
 $to = t...@address.com;
 $subject = Hello!;
 $body = Hello!;
 
 $host = mail.host.net;
 $username = myuser;
 $password = mypass;
 
 $headers = array ('From' = $from,'To' = $to,'Subject' = $subject);
 $smtp = Mail::factory('smtp',array ('host' = $host,'auth' = 
 true,'username' = $username,'password' = $password));
 
 I'd suggest putting a check here to see if $smtp is a PEAR::Error
 object as well:
 
 if (PEAR::isError($smtp)) {
  echo (p . $smtp-getMessage() . /p);
  // die or return or skip the next part, whatever
 } else {

Same result… which is to say no error returned even for messages sent with no 
email in the to address field.

--Rick


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



[PHP] Pear Mail - Trap for errors?

2012-11-14 Thread Rick Dwyer
Hello all.

I have some Pear Mail code composing an email and sending it to an external 
smtp server for sending. 

The issue is determining whether that external server actually accepted the 
mail or not.  In the IF(PEAR… code below, it will return success even if I 
leave the $to value empty.  However, if I remove the smtp username or password, 
it will return an error indicating it could not reach the remote server.  So 
the Pear::IsError function seems to only reflect if the intended server was 
accessible… and not if the intended server accepted the outgoing email for 
delivery.

Anyone have experience with the scenario below… specifically with determining 
if the smtp server accepted the mail for delivery?

Thanks for any info.

--Rick






 require_once Mail.php;
 
 $from = f...@address.com;
 $to = t...@address.com;
 $subject = Hello!;
 $body = Hello!;
 
 $host = mail.host.net;
 $username = myuser;
 $password = mypass;
 
 $headers = array ('From' = $from,'To' = $to,'Subject' = $subject);
 $smtp = Mail::factory('smtp',array ('host' = $host,'auth' = true,'username' 
= $username,'password' = $password));
 
 $mail = $smtp-send($to, $headers, $body);
 
 if (PEAR::isError($mail)) {
   echo(p . $mail-getMessage() . /p);
  } else {
   echo(pMessage successfully sent!/p);
  }
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP to decode AES

2012-10-18 Thread Rick Dwyer
Hello all.

Has anyone ever tried to decode a JAVA AES/CBC encrypted string with PHP before?

I found a tutorial online with the following code to use as starting point, but 
it fails to return anything readable:

$code ='Hello World';
$key = 'my key';

function decrypt($code, $key) {
$key = hex2bin($key);
$code = hex2bin($code);
$td = mcrypt_module_open(rijndael-128, , cbc, );
mcrypt_generic_init($td, $key, fedcba9876543210);
$decrypted = mdecrypt_generic($td, $code);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return utf8_encode(trim($decrypted));
}


function hex2bin($hexdata) {
$bindata = ;
for ($i = 0; $i  strlen($hexdata); $i += 2) {
$bindata .= chr(hexdec(substr($hexdata, $i, 2)));
}
return $bindata;
}
echo decrypt($code, $key);

The above returns output containing a series of unprintable characters.

I thought maybe it was due to $code not being in a hex format, but after 
converting to hex and resubmitting, I still unprintable characters.

Any info is appreciated.



 
 --Rick



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



Re: [PHP] PHP to decode AES

2012-10-18 Thread Rick Dwyer
To correct what I posted below, $code that I'm passing to my function is 
encrypted… not plain text:

ch7WvaSrCiHLstNeNUp5SkPfPgw0Z8vrNPJT+9vU7jN/C
 
 --Rick


On Oct 18, 2012, at 12:06 PM, Rick Dwyer rpdw...@earthlink.net wrote:

 Hello all.
 
 Has anyone ever tried to decode a JAVA AES/CBC encrypted string with PHP 
 before?
 
 I found a tutorial online with the following code to use as starting point, 
 but it fails to return anything readable:
 
 $code ='Hello World';
 $key = 'my key';
 
 function decrypt($code, $key) {
 $key = hex2bin($key);
 $code = hex2bin($code);
 $td = mcrypt_module_open(rijndael-128, , cbc, );
 mcrypt_generic_init($td, $key, fedcba9876543210);
 $decrypted = mdecrypt_generic($td, $code);
 mcrypt_generic_deinit($td);
 mcrypt_module_close($td);
 return utf8_encode(trim($decrypted));
 }
 
 
 function hex2bin($hexdata) {
 $bindata = ;
 for ($i = 0; $i  strlen($hexdata); $i += 2) {
 $bindata .= chr(hexdec(substr($hexdata, $i, 2)));
 }
 return $bindata;
 }
 echo decrypt($code, $key);
 
 The above returns output containing a series of unprintable characters.
 
 I thought maybe it was due to $code not being in a hex format, but after 
 converting to hex and resubmitting, I still unprintable characters.
 
 Any info is appreciated.
 
 
 
 
 --Rick
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


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



Re: [PHP] PHP to decode AES

2012-10-18 Thread Rick Dwyer
On Oct 18, 2012, at 2:38 PM, Matijn Woudt tijn...@gmail.com wrote:

 On Thu, Oct 18, 2012 at 7:19 PM, Rick Dwyer rpdw...@earthlink.net wrote:
 To correct what I posted below, $code that I'm passing to my function is 
 encrypted… not plain text:
 
 ch7WvaSrCiHLstNeNUp5SkPfPgw0Z8vrNPJT+9vU7jN/C
 
 --Rick
 
 
 On Oct 18, 2012, at 12:06 PM, Rick Dwyer rpdw...@earthlink.net wrote:
 
 Hello all.
 
 Has anyone ever tried to decode a JAVA AES/CBC encrypted string with PHP 
 before?
 
 I found a tutorial online with the following code to use as starting point, 
 but it fails to return anything readable:
 
 $code ='Hello World';
 $key = 'my key';
 
 function decrypt($code, $key) {
 $key = hex2bin($key);
 $code = hex2bin($code);
 $td = mcrypt_module_open(rijndael-128, , cbc, );
 mcrypt_generic_init($td, $key, fedcba9876543210);
 $decrypted = mdecrypt_generic($td, $code);
 mcrypt_generic_deinit($td);
 mcrypt_module_close($td);
 return utf8_encode(trim($decrypted));
 }
 
 
 function hex2bin($hexdata) {
 $bindata = ;
 for ($i = 0; $i  strlen($hexdata); $i += 2) {
 $bindata .= chr(hexdec(substr($hexdata, $i, 2)));
 }
 return $bindata;
 }
 echo decrypt($code, $key);
 
 The above returns output containing a series of unprintable characters.
 
 I thought maybe it was due to $code not being in a hex format, but after 
 converting to hex and resubmitting, I still unprintable characters.
 
 Any info is appreciated.
 
 --Rick
 
 
 Your key is not in hexadecimal, could it be Base64?

I tried base64_decode($code) without luck as well.

--Rick

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


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



Re: [PHP] PHP to decode AES

2012-10-18 Thread Rick Dwyer
On Oct 18, 2012, at 4:39 PM, Adam Richardson simples...@gmail.com wrote:

 On Thu, Oct 18, 2012 at 12:06 PM, Rick Dwyer rpdw...@earthlink.net wrote:
 Hello all.
 
 Has anyone ever tried to decode a JAVA AES/CBC encrypted string with PHP 
 before?
 
 I found a tutorial online with the following code to use as starting point, 
 but it fails to return anything readable:
 
 $code ='Hello World';
 $key = 'my key';
 
 function decrypt($code, $key) {
 $key = hex2bin($key);
 $code = hex2bin($code);
 $td = mcrypt_module_open(rijndael-128, , cbc, );
 mcrypt_generic_init($td, $key, fedcba9876543210);
 $decrypted = mdecrypt_generic($td, $code);
 mcrypt_generic_deinit($td);
 mcrypt_module_close($td);
 return utf8_encode(trim($decrypted));
 }
 
 
 function hex2bin($hexdata) {
 $bindata = ;
 for ($i = 0; $i  strlen($hexdata); $i += 2) {
 $bindata .= chr(hexdec(substr($hexdata, $i, 2)));
 }
 return $bindata;
 }
 echo decrypt($code, $key);
 
 The above returns output containing a series of unprintable characters.
 
 I thought maybe it was due to $code not being in a hex format, but after 
 converting to hex and resubmitting, I still unprintable characters.
 
 Any info is appreciated.
 
 Can you post the Java code you're using? There are things such as the
 padding specification that could cause some issues.
 
 Adam
 

Hi all.  We were able to get it to work.  But thank you for your replies.

But for anyone interested (including anyone who has emailed me privately 
implying I was up to something untoward), the specs from the client were as 
follows:

Unencrypted: 2012-10-18T10:57:43+0200 someurl.com
Encrypted + base64: ch7WvaSrCiHLstNeNUp5SkPfPGqZ8vrNPJT+9vU7jN/C
Encrypt algorithm: AES/CBC, PKCS5Padding, IV of 16 NULL (0x0 hex) bytes
Key: someKEY123-12346



$iv = mcrypt_create_iv(32);
$key = 'someKEY123-12346';
$text = '2012-10-18T10:57:43+0200 someurl.com';
$size = mcrypt_get_block_size('rijndael-128', 'cbc');
$text = pkcs5_pad($text, $size); 
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, 
$iv);

$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, 
base64_decode('ch7WvaSrCiHLstNeNUp5SkPfPGqZ8vrNPJT+9vU7jN/C'), MCRYPT_MODE_CBC, 
$iv);


function pkcs5_pad ($text, $blocksize)
{
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}


echo $decrypttext;
… 




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



[PHP] Serving an image

2012-10-15 Thread Rick Dwyer
Hello all.

I am sending an email with a logo at the top of the email.  The source of the 
image for the logo is:

http://myurl.com/image.php?id=5

Image.php then calls a function that simply returns the following:



$image='img src=http://myurl.com/images/logo.jpg; /';
return $image;



Calling the page directly via the URL http://myurl.com/image.php?id=5 works 
fine.
But when the email is opened, I get the broken link/image icon even though I 
can see in my source that the URL which works when loaded into a browser.

What needs to be done to serve that image to a email client when it is opened?

Thanks,


 
 --Rick



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



[PHP] Array_diff problems

2012-04-27 Thread Rick Dwyer
Hello all.

I have two arrays and when compared against each other via array_diff, I do not 
get any output:

$myarray1 = Array ( 
[0] = Array ( [id] = 1 [Funding_Type] = Federal [Amount] = 10 
[Frequency_Description] = Total [Other_Funding] = ) 
[1] = Array ( [id] = 2 [Funding_Type] = Trust [Amount] = 20 
[Frequency_Description] = Per Year [Other_Funding] = ) 
[2] = Array ( [id] = 3 [Funding_Type] = Other Funding [Amount] = 30 
[Frequency_Description] = Other [Other_Funding] = some )) 

$myarray2 = Array 
( 
[0] = Array ( [id] = 1 [Funding_Type] = Federal [Amount] = 10 
[Frequency_Description] = Total [Other_Funding] = ) 
[1] = Array ( [id] = 2 [Funding_Type] = Trust [Amount] = 20 
[Frequency_Description] = Per Year [Other_Funding] = ) 
[2] = Array ( [id] = 3 [Funding_Type] = Other Funding [Amount] = 50 
[Frequency_Description] = Other [Other_Funding] = none )) 

$arraydifferences = (array_diff($myarray1,$myarray2));

I need $arraydifferences to record the differences between the two.

Any help is appreciated.

Thanks,
 
 --Rick



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



Re: [PHP] Array_diff problems

2012-04-27 Thread Rick Dwyer
Thanks to both for the direction.


 
 --Rick
On Apr 27, 2012, at 4:13 PM, Jim Giner wrote:

 
 
 Are these arrays nested in an array?  In that case the manual says you have 
 to do the compare differently.


On Apr 27, 2012, at 4:19 PM, admin wrote:

 
 
 -Original Message-
 From: Rick Dwyer [mailto:rpdw...@earthlink.net] 
 Sent: Friday, April 27, 2012 3:37 PM
 To: PHP-General
 Subject: [PHP] Array_diff problems
 
 Hello all.
 
 I have two arrays and when compared against each other via array_diff, I do
 not get any output:
 
 $myarray1 = Array (
 [0] = Array ( [id] = 1 [Funding_Type] = Federal [Amount] = 10
 [Frequency_Description] = Total [Other_Funding] = ) [1] = Array ( [id] =
 2 [Funding_Type] = Trust [Amount] = 20 [Frequency_Description] = Per Year
 [Other_Funding] = ) [2] = Array ( [id] = 3 [Funding_Type] = Other
 Funding [Amount] = 30 [Frequency_Description] = Other [Other_Funding] =
 some )) 
 
 $myarray2 = Array
 (
 [0] = Array ( [id] = 1 [Funding_Type] = Federal [Amount] = 10
 [Frequency_Description] = Total [Other_Funding] = ) [1] = Array ( [id] =
 2 [Funding_Type] = Trust [Amount] = 20 [Frequency_Description] = Per Year
 [Other_Funding] = ) [2] = Array ( [id] = 3 [Funding_Type] = Other
 Funding [Amount] = 50 [Frequency_Description] = Other [Other_Funding] =
 none )) 
 
 $arraydifferences = (array_diff($myarray1,$myarray2));
 
 I need $arraydifferences to record the differences between the two.
 
 Any help is appreciated.
 
 Thanks,
 
 --Rick
 
 
 
 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
 http://www.php.net/unsub.php
 
 
 
 I suggest you read Multidimensional array_diff for Nested Arrays and your
 format is not correct on the array that you gave an example of.
 
 http://www.php.net/manual/en/function.array-diff.php#98680
 
 
 
 
 
 
 


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



[PHP] Insert group by

2012-04-26 Thread Rick Dwyer
Hello all.

This is more of a MySQL question, but I'm hoping it can be answered here.
On one of my pages, I issue a SQL command to group data as such:

$sql='select count(*) as count, searchkeywords from searchkeywords group by 
searchkeywords order by count desc'

Works well... but I would like it to groups plurals with singular words as 
well.  So hats are grouped with hat.

Since I'm doing a group by column name, I don't know that this can be done.

Any help is appreciated.

Thanks,
 
 --Rick



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



[PHP] Selecting checkboxes based on SQL query

2012-02-23 Thread Rick Dwyer

Hello all.

I perform a SQL query like the following:

$sql = 'select * from my_table where id=10

It returns the the following array for 3 records:


Array ( [0] = Array ( [cb] = 2 ) [1] = Array ( [cb] = 6 ) [2] =  
Array ( [cb] = 1 ) )


The values of CB in the above array are the values of html checkboxes  
on a page.


input type=checkbox name=cb[ ] value=1...
input type=checkbox name=cb[ ] value=2...
input type=checkbox name=cb[ ] value=3...
input type=checkbox name=cb[ ] value=4... etc

If the above array's cb value matches the value of a checkbox on the  
page, I need the default state of the checkbox to be checked so I  
know I'm going to have some ternary logic in each html checkbox.  But  
I don't know how to create a custom function from the above array to  
provide that logic.  I've tried some tutorials, but with no success as  
the array I am receiving is not like those in the tutorials.


Any help would be greatly appreciated.

Thank you.


 --Rick



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



Re: [PHP] Selecting checkboxes based on SQL query

2012-02-23 Thread Rick Dwyer

I should have been more explicit in my description...

The SQL command that returns the array is not the same one that  
creates the checkboxes they are two different sql queries and I  
would prefer to keep them that way.


I actually have it working for a form submit with a custom function I  
got off the web.  But the custom function relies on the array it's  
working on to look like this:


[cb] = Array ( [0] = 1 [1] = 6 [2] = 2 [3] = 4 [4] = 3 )


So, to use my existing function, how do I get the following array to  
look like the above one:


Array ( [0] = Array ( [cb] = 2 ) [1] = Array ( [cb] = 6 ) [2] =  
Array ( [cb] = 1 ) )



 --Rick


On Feb 23, 2012, at 2:08 PM, Fatih P. wrote:

On Thu, Feb 23, 2012 at 8:49 PM, Rick Dwyer rpdw...@earthlink.net  
wrote:



Hello all.

I perform a SQL query like the following:

$sql = 'select * from my_table where id=10

It returns the the following array for 3 records:


Array ( [0] = Array ( [cb] = 2 ) [1] = Array ( [cb] = 6 ) [2]  
= Array

( [cb] = 1 ) )

The values of CB in the above array are the values of html  
checkboxes on a

page.

input type=checkbox name=cb[ ] value=1...
input type=checkbox name=cb[ ] value=2...
input type=checkbox name=cb[ ] value=3...
input type=checkbox name=cb[ ] value=4... etc

If the above array's cb value matches the value of a checkbox on  
the page,
I need the default state of the checkbox to be checked so I  
know I'm
going to have some ternary logic in each html checkbox.  But I  
don't know
how to create a custom function from the above array to provide  
that logic.
I've tried some tutorials, but with no success as the array I am  
receiving

is not like those in the tutorials.

Any help would be greatly appreciated.

Thank you.


--Rick



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



replace the name part as following

input type=checkbox name=cb[put_the_id_here] value=1.


when dumping into html from array


foreach ($sql_result as $value) {
  if ($value == $selected) {
  input type checkbox name=cb[$value['id']] value=$value['id']
checked=checked
  } else {
   input type checkbox name=cb[$value['id']]   value=$value['id']
  }
}

hope this helps



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



[PHP] Form Post to different domain

2012-02-14 Thread Rick Dwyer

Hello all.

If I have a form on domain A that uses POST to submit data and I want  
to submit the form to domain B on an entirely different server, how do  
I pull the form values (... echo $_POST[myval] returns nothing)  
from the form at domain B?



 --Rick



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



Re: [PHP] Form Post to different domain

2012-02-14 Thread Rick Dwyer

On Feb 14, 2012, at 1:16 PM, Daniel Brown wrote:

On Tue, Feb 14, 2012 at 13:14, Rick Dwyer rpdw...@earthlink.net  
wrote:

Hello all.

If I have a form on domain A that uses POST to submit data and I  
want to
submit the form to domain B on an entirely different server, how do  
I pull
the form values (... echo $_POST[myval] returns nothing) from  
the form

at domain B?


   First (basic, obvious) question: do you have full access to both
domains, or is Domain B a third-party site?



I only have access to domain B... the one receiving the Form POST.

--Rick


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



Re: [PHP] Form Post to different domain

2012-02-14 Thread Rick Dwyer

Thanks Dan.

As it turned out the reason for not showing the passed values is that  
I didn't have www in the destination address and the values must  
have been getting lost when Apache redirected requests without www to  
the fully formed URL.



 --Rick


On Feb 14, 2012, at 1:39 PM, Daniel Brown wrote:

On Tue, Feb 14, 2012 at 13:36, Rick Dwyer rpdw...@earthlink.net  
wrote:


I only have access to domain B... the one receiving the Form POST.


   Then all you should need to do is:

   a.) Verify that Domain A is indeed pointing to Domain B, to
the script you expect, as a POST request.
   b.) In the POST-receiving script on Domain B, try this simple  
snippet:


?php
echo 'pre'.PHP_EOL;
var_dump($_POST);
die('/pre');
?

   That should give you all data from the post request.

--
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

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




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



[PHP] Curl problems

2012-01-11 Thread Rick Dwyer

Hello all.

I use curl to make a call to another page on my site... but it  
operates erroneously sometimes working... sometimes not.  The page  
it calls creates an email and I can see on the server the email in the  
queue when it's working.  If I echo out the URL the curl command is  
supposed to load and load it manually, it works without fail.


Any help on what I am doing wrong below is greatly appreciated.

Thanks.


$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'https://mydomain.com/email_confirmation.htm?id_order='.$id_order.'sess_id='.$sess_id) 
;

curl_exec($curl_handle);
curl_close($curl_handle);

 --Rick



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



Re: [PHP] Curl problems

2012-01-11 Thread Rick Dwyer

On Jan 11, 2012, at 6:29 PM, Matijn Woudt wrote:

On Thu, Jan 12, 2012 at 12:20 AM, Rick Dwyer rpdw...@earthlink.net  
wrote:

Hello all.

I use curl to make a call to another page on my site... but it  
operates
erroneously sometimes working... sometimes not.  The page it  
calls
creates an email and I can see on the server the email in the queue  
when
it's working.  If I echo out the URL the curl command is supposed  
to load

and load it manually, it works without fail.

Any help on what I am doing wrong below is greatly appreciated.

Thanks.


$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'https://mydomain.com/email_confirmation.htm?id_order='.$id_order.'sess_id='.$sess_id) 
;

curl_exec($curl_handle);
curl_close($curl_handle);

 --Rick


It's maybe not a real answer to your question, but if all you want to
do is call that page, why don't you just use
file_get_contents(https://mydomain.com/email_confirmation.htm?id_order='.$id_order.'sess_id='.$sess_id 
);

(See [1])
It works out of the box, and I have found curl unstable too sometimes.

Matijn


Thanks Matijn,
But I get Notice: file_get_contents() [function.file-get-contents]:  
Unable to find the wrapper https - did you forget to enable it when  
you configured PHP?... I'm using a hosting provider and I don't  
believe they will enable this for security reasons.


--Rick



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



Re: [PHP] PHP page source charset

2011-12-20 Thread Rick Dwyer


On Dec 20, 2011, at 1:32 PM, Jim Lucas wrote:


On 12/19/2011 6:44 PM, Rick Dwyer wrote:

Hello all.

When I set my page charset from iso-8859-1 to utf-8, when I run it  
through the
W3C validator, the validator returns an error that it can't  
validate the page

because of an illegal character not covered by UTF-8.


Sorry, I am unable to validate this document because on line 199  
it contained
one or more bytes that I cannot interpret as utf-8(in other words,  
the bytes
found are not valid values in the specified Character Encoding).  
Please check

both the content of the file and the character encoding indication.
The error was: utf8 \x99 does not map to Unicode

Line 199 is a line with my open PHP declaration:
?php

Not sure why W3C is having a hard time with this.  Any ideas?

--Rick




You need to look at the output of your script, not the source for  
your script.


The validation only happens after PHP has executed  processed the  
php script
and sent the output to the browser.  It is the source in the browser  
that the

validation script sees.

--
Jim Lucas

Don't know what I was thinking when asked this as I am well aware PHP  
is server side and already rendered at the point of the W3C validator.


--Rick


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



[PHP] PHP page source charset

2011-12-19 Thread Rick Dwyer

Hello all.

When I set my page charset from iso-8859-1 to utf-8, when I run it  
through the W3C validator, the validator returns an error that it  
can't validate the page because of an illegal character not covered by  
UTF-8.



Sorry, I am unable to validate this document because on line 199 it  
contained one or more bytes that I cannot interpret as utf-8(in other  
words, the bytes found are not valid values in the specified Character  
Encoding). Please check both the content of the file and the character  
encoding indication.

The error was: utf8 \x99 does not map to Unicode

Line 199 is a line with my open PHP declaration:
?php

Not sure why W3C is having a hard time with this.  Any ideas?

 --Rick


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



[PHP] Preferred Syntax

2011-12-14 Thread Rick Dwyer

Hello all.

Can someone tell me which of the following is preferred and why?

 echo a style='text-align:left;size:14;font-weight:bold' href='/ 
mypage.php/$page_id'$page_name/abr;


 echo a style='text-align:left;size:14;font-weight:bold' href='/ 
mypage.php/.$page_id.'.$page_name./abr;


When I come across the above code in line 1, I have been changing it  
to what you see in line 2 for no other reason than it delineates out  
better in BBEdit.  Is this just a preference choice or is one method  
better than the other?


 --Rick



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



Re: [PHP] Preferred Syntax

2011-12-14 Thread Rick Dwyer
On Dec 14, 2011, at 1:53 PM, ad...@buskirkgraphics.com ad...@buskirkgraphics.com 
 wrote:


The key thing to remember here is that this is a preference and not a
performance thing.


Thank you... this is basically what I wanted to know.  I was concerned  
that not breaking the VARS out separately from the echo'ed text might  
cause some sort of performance problem or confusion for PHP.   
Therefore, whenever I came across them, I was breaking them out with  
the . $var . technique.  Will no longer do that for existing code, as  
it appears not necessary, but I do prefer it for readability sake...  
expecially in BBEdit.  So will continue to write new code breaking it  
out.  And I too prefer a single quote for PHP and a double for HTML...  
even though the sample I displayed showed otherwise.


Thanks to all who responded.

--Rick



[PHP] mcrypt_encrypt help needed

2011-11-30 Thread Rick Dwyer

Hello all.

I am using the following function to encrypt a string:

define('SALT', 'myvalueforsalthere');

function encrypt($text)
{
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256,  
SALT, $text, MCRYPT_MODE_ECB,  
mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,  
MCRYPT_MODE_ECB), MCRYPT_RAND;

}

and then:

$myval=hello;
$mayval= encrypt($myval);


echo decrypt($myval);

returns hello great.



But when my input string is more complicated I get unprintable  
characters out of the decyrpt side:


$myval=var1=1var2=2var3=3;

The above when decrypted will spit out a string of unprintable  
characters.

Is encrypt/decrypt choking on the = sign?  I tried:

$myval=htmlentities($myval);

But it did not work.  Any help is appreciated.

Thanks,

--Rick



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



Re: [PHP] mcrypt_encrypt help needed

2011-11-30 Thread Rick Dwyer

My decrypt is below:

$myval=$_GET[myval];


// let the encryption begin
define('SALT', 'myvalueforsalthere');

function decrypt($text)
{
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT,  
base64_decode($text), MCRYPT_MODE_ECB,  
mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,  
MCRYPT_MODE_ECB), MCRYPT_RAND)));

}

echo decrypt($myval);



--Rick


On Nov 30, 2011, at 4:14 PM, Adam Richardson wrote:

On Wed, Nov 30, 2011 at 3:57 PM, Rick Dwyer rpdw...@earthlink.net  
wrote:



Hello all.

I am using the following function to encrypt a string:

define('SALT', 'myvalueforsalthere');

function encrypt($text)
{
  return trim(base64_encode(mcrypt_**encrypt(MCRYPT_RIJNDAEL_256,  
SALT,
$text, MCRYPT_MODE_ECB,  
mcrypt_create_iv(mcrypt_get_**iv_size(MCRYPT_RIJNDAEL_256,

MCRYPT_MODE_ECB), MCRYPT_RAND;
}

and then:

$myval=hello;
$mayval= encrypt($myval);


echo decrypt($myval);

returns hello great.



But when my input string is more complicated I get unprintable  
characters

out of the decyrpt side:

$myval=var1=1var2=2var3=3;

The above when decrypted will spit out a string of unprintable  
characters.

Is encrypt/decrypt choking on the = sign?  I tried:

$myval=htmlentities($myval);

But it did not work.  Any help is appreciated.

Thanks,

--Rick



Hi Rick,

Can you show us the decrypt function, too (even though it should be  
just
the reverse order of operations using a decrypt function, I'd just  
like to
double check it before commenting.) By the way, I wouldn't recommend  
using

ECB mode unless you have a special circumstance:
http://www.quora.com/Is-AES-ECB-mode-useful-for-anything

Adam

(Sorry for the duplicate, Rick, I forgot to reply all the first time.)

--
Nephtali:  A simple, flexible, fast, and security-focused PHP  
framework

http://nephtaliproject.com



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



Re: [PHP] mcrypt_encrypt help needed

2011-11-30 Thread Rick Dwyer

On Nov 30, 2011, at 5:13 PM, Matijn Woudt wrote:




Your decrypt function seems fine, and the encrypt/decrypt functions
work fine both in the same file for me. Now you say you use
$_GET[myval], which means you get them from URL. Base64 is not URL
safe, have you used urlencode()?

Matijn




OK, the problem appears to be  that my string encoded contains a +  
symbol:


Sw+ht0agaQRBpFlfHSucpYZ

So I rawurlencode it and if I echo it out, it appears correctly on the  
page as:


Sw%2Bht0agaQRBpFlfHSucpYZ 

BUT... when I pass this encrypted value off to PayPal (I'm integrating  
with them), encoded, when they return me to my site, instead of  
passing me my value as above, they are somehow decoding back to the  
original:


Sw+ht0agaQRBpFlfHSucpYZ

As I can see it in the URL.  The + symbol is then interpretted as a  
space instead of + symbol and a result, my decrypt function fails.


So I send off the encrypted value encoded to PayPal but when they go  
to redirect back to my site after payment has been made, instead of  
the url with Sw%2Bht0agaQRBpFlfHSucpYZ  in it, they are decoding  
it so my url contains Sw+ht0agaQRBpFlfHSucpYZ which causes me  
problems.


Is there alternative encrypting scheme that will not need url encoding  
(so I can be sure the passed url back from PayPal is ok as is)?


--Rick



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



Re: [PHP] mcrypt_encrypt help needed

2011-11-30 Thread Rick Dwyer

On Nov 30, 2011, at 7:38 PM, Matijn Woudt wrote:

On Thu, Dec 1, 2011 at 1:14 AM, Rick Dwyer rpdw...@earthlink.net  
wrote:

On Nov 30, 2011, at 5:13 PM, Matijn Woudt wrote:




Your decrypt function seems fine, and the encrypt/decrypt functions
work fine both in the same file for me. Now you say you use
$_GET[myval], which means you get them from URL. Base64 is not URL
safe, have you used urlencode()?

Matijn




OK, the problem appears to be  that my string encoded contains a +  
symbol:


Sw+ht0agaQRBpFlfHSucpYZ

So I rawurlencode it and if I echo it out, it appears correctly on  
the page

as:

Sw%2Bht0agaQRBpFlfHSucpYZ 

BUT... when I pass this encrypted value off to PayPal (I'm  
integrating with
them), encoded, when they return me to my site, instead of passing  
me my

value as above, they are somehow decoding back to the original:

Sw+ht0agaQRBpFlfHSucpYZ

As I can see it in the URL.  The + symbol is then interpretted as a  
space

instead of + symbol and a result, my decrypt function fails.

So I send off the encrypted value encoded to PayPal but when they  
go to
redirect back to my site after payment has been made, instead of  
the url
with Sw%2Bht0agaQRBpFlfHSucpYZ  in it, they are decoding it so  
my url

contains Sw+ht0agaQRBpFlfHSucpYZ which causes me problems.

Is there alternative encrypting scheme that will not need url  
encoding (so I

can be sure the passed url back from PayPal is ok as is)?

--Rick


It seems normal to me that it is decoded, I think that's how it's
supposed to work. How about urlencoding it twice? That might just
work.
Other possibility is to send it as a string of hex characters using
hex2bin or something like that.

Matijn


Yes!  Thanks, double urlencoding it did the trick.

I first encrypt it followed by a double rawurlencode.

Thanks... my head was beginning to really hurt from banging it on the  
wall.


--Rick



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



[PHP] Writing out errors to a file

2011-11-03 Thread Rick Dwyer

Hello all.
How do I get PHP to write out any errors or warnings to a text file  
that I can review and go through to troubleshoot issues?
I don't have access to the ini file... so I was hoping for a simple  
write to a file at the web root.


Thanks,


 --Rick



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



[PHP] PHP and webmaster tools

2011-11-02 Thread Rick Dwyer

Hello list.

I am looking for someone who knows PHP and has extensive
experience with webmaster tools.

I have a series of crawl errors I need resolved but cannot find the
bad URL's anywhere on the site.

Please contact me off list.

Thanks,

 --Rick



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



Re: [PHP] function.session-start in Webmaster Tools

2011-10-31 Thread Rick Dwyer
But those pages, when loaded, do not display any PHP errors.  Only  
webmaster tools is showing the function.session-start in a link to  
that page.  When I looked up hte meaning of session-start function, I  
found others who have indicated that white space in front of the  
session tag can cause this... so I eliminated it.  Not sure if that  
will fix as the page has never displayed an error and Google takes  
forever to recrawl the whole site.



 --Rick


On Oct 31, 2011, at 5:44 AM, Stuart Dallas wrote:


On 30 Oct 2011, at 20:30, Rick Dwyer wrote:


Hello all.

Not sure just how much of this is PHP related, but hoping someone  
has come across this before.


I Google's webmaster tools for a site I work on, they list more  
than 100 crawl errors for pages with URL's as follows:


http://mydomain.com/My-Directory/function.session-start

Can anyone explain why webmaster tools is seeing pages with links  
ending in function.session-start?  I read up on the error  
itself... sometimes caused by whitespace before the session_start  
tag... have fixed that.  Any info is appreciated.



You have PHP errors somewhere on your site. The error messages  
contain links that could result in those URLs. Find out what pages  
are linking to those URLs and check them for errors.


-Stuart

--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/



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



[PHP] function.session-start in Webmaster Tools

2011-10-30 Thread Rick Dwyer

Hello all.

Not sure just how much of this is PHP related, but hoping someone has  
come across this before.


I Google's webmaster tools for a site I work on, they list more than  
100 crawl errors for pages with URL's as follows:


http://mydomain.com/My-Directory/function.session-start

Can anyone explain why webmaster tools is seeing pages with links  
ending in function.session-start?  I read up on the error itself...  
sometimes caused by whitespace before the session_start tag... have  
fixed that.  Any info is appreciated.




 --Rick



[PHP] Displaying variables in text - clarification needed

2011-10-26 Thread Rick Dwyer

Hello all.

I inherited some PHP pages about a year ago.  They have been fine all  
along but now a bunch of erroneous errors and results are popping up.   
I traced it to the way the variables were being used on the page...  
for example, the following SQL statement (a space between ' and  for  
clarity):



sql=select name from mytable where name=$myvar and display='yes' ;

This has worked in the past but is now returning errors for some  
records and working for others.  I changed the above to the following  
and now all is good:


sql=select name from mytable where name=' .$myvar. ' and  
display='yes' ;


What would explain why the former is suddenly causing problems?  The  
version of PHP is 5.2.3 and from what I can tell, hasn't been updated  
since February of 2011.


Thanks,

 --Rick



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



[PHP] PHP Rounding Question

2011-05-20 Thread Rick Dwyer
I have a division formula that will return an value from 0.00 to 5...  
so I can get values like 2.38 or 4.79.


However, never lower than 0 or higher than 5.

How do I coerce the result to always round up to the nearest increment  
1/4?  So for example:


2.06 gets rounded to 2.25
0.01 gets rounded to 0.25
4.28 gets rounded to 4.50
3.71 gets rounded to 3.75

Thanks,

 --Rick



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



[PHP] Destroying cookies... not working

2011-04-27 Thread Rick Dwyer

Hello all.

I have a logout page that should be destroying cookies when loaded...  
but it is not.


setcookie(mycookie, False, time() - 3600, /);

However, I can still pull values stored in the cookie and I can still  
see the cookie in my browser's Show Cookies window.


So I tried the following:

setcookie('mycookie','',time()-3600);
unset($_COOKIE['mycookie']);

Still no luck.

Any help with this is appreciated.



 --Rick

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



Re: [PHP] Destroying cookies... not working

2011-04-27 Thread Rick Dwyer

The following did the trick... is there any reason I should not use it?

$name=mysession;
setcookie($name);

 --Rick


On Apr 27, 2011, at 7:16 PM, Rick Dwyer wrote:


Hello all.

I have a logout page that should be destroying cookies when  
loaded... but it is not.


setcookie(mycookie, False, time() - 3600, /);

However, I can still pull values stored in the cookie and I can  
still see the cookie in my browser's Show Cookies window.


So I tried the following:

setcookie('mycookie','',time()-3600);
unset($_COOKIE['mycookie']);

Still no luck.

Any help with this is appreciated.



--Rick

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




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



[PHP] Memory_Limit adjustments

2011-01-06 Thread Rick Dwyer

Hello all.

I am using a form combined with PHP to upload files to a website  
directory.
Worked fine until I tried to upload a file 1.7 mb in size.  My php  
code isn't the bottleneck as I scan the file first and reject the  
upload request if it exceed 4096KB.


So I looked at the php.ini file and tweaked some settings.  Once I  
changed the Memory_Limit setting from 8mb to 28mb, the file upload  
without a problem.


So, my question is, is the 28mb setting going to cause problems  
elsewhere on the server or is this a relatively modest setting?   
Should I adjust it further?


The server is a Linux server running Apache 1.3.37 with PHP version  
5.2.3.

Current memory usage as follows:

Current Memory Usage
total   used   free
Mem:  21898120 283912   21614208
-/+ buffers/cache:  283912   21614208
Swap: 0 00
Total:21898120 283912   21614208




Thanks for any help.


 --Rick



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



[PHP] Parsing a phrase

2010-12-12 Thread Rick Dwyer

Hello all.

I have a page where the user can enter a search phrase and upon  
submitting, the search phrase is queried in MySQL.


However, I need to modify is so each word in the phrase is searched  
for... not just the exact phrase.


So, big blue hat will return results like:

A big hat - blue in color
Hat - blue, big

SQL would look like 

WHERE (item_description like %big% and item_description like %blue 
%  and item_description like %hat% )


So, via PHP, what is the best way to extract each word from the search  
phrase to it's own variable so I can place them dynamically into the  
SQL statement.


Thanks,


 --Rick



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



Re: [PHP] Re: Parsing a phrase

2010-12-12 Thread Rick Dwyer

Thanks Nathan.
The MySQL Match/Against will probably work well... but I would need to  
somehow add a + to the beginning of each word in the phrase so PHP  
will still be involved.



 --Rick


On Dec 12, 2010, at 2:51 PM, Nathan Rixham wrote:


Rick Dwyer wrote:

Hello all.
I have a page where the user can enter a search phrase and upon  
submitting, the search phrase is queried in MySQL.
However, I need to modify is so each word in the phrase is searched  
for... not just the exact phrase.

So, big blue hat will return results like:
A big hat - blue in color
Hat - blue, big
SQL would look like 
WHERE (item_description like %big% and item_description like  
%blue%  and item_description like %hat% )


You may be better to use full text and MATCH for this, see:

http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html

However..

So, via PHP, what is the best way to extract each word from the  
search phrase to it's own variable so I can place them dynamically  
into the SQL statement.


There are many ways you can do this:

 http://php.net/explode
 http://php.net/str_split
 http://php.net/preg_split

Many examples can be found on the above pages, and you're real  
solution depends on how many edge-cases you want to cover, but the  
above will cover most approaches :)


Best,

Nathan

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




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



Re: [PHP] Re: Parsing a phrase

2010-12-12 Thread Rick Dwyer

I have it working now using preg_replace.

 --Rick


On Dec 12, 2010, at 3:50 PM, Rick Dwyer wrote:


Thanks Nathan.
The MySQL Match/Against will probably work well... but I would need  
to somehow add a + to the beginning of each word in the phrase so  
PHP will still be involved.



--Rick


On Dec 12, 2010, at 2:51 PM, Nathan Rixham wrote:


Rick Dwyer wrote:

Hello all.
I have a page where the user can enter a search phrase and upon  
submitting, the search phrase is queried in MySQL.
However, I need to modify is so each word in the phrase is  
searched for... not just the exact phrase.

So, big blue hat will return results like:
A big hat - blue in color
Hat - blue, big
SQL would look like 
WHERE (item_description like %big% and item_description like  
%blue%  and item_description like %hat% )


You may be better to use full text and MATCH for this, see:

http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html

However..

So, via PHP, what is the best way to extract each word from the  
search phrase to it's own variable so I can place them dynamically  
into the SQL statement.


There are many ways you can do this:

http://php.net/explode
http://php.net/str_split
http://php.net/preg_split

Many examples can be found on the above pages, and you're real  
solution depends on how many edge-cases you want to cover, but the  
above will cover most approaches :)


Best,

Nathan

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




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




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



[PHP] PHP loop to issue sql insert

2010-11-14 Thread Rick Dwyer

Hello List.

I have a sql command that counts, groups and sorts data from a table.   
I need to insert the results of that sql command into different table.


My sql SELECT looks like  this:

select count(*) as count, searchkeywords from searchtable group by  
searchkeywords order by count desc;


and returns records like this:

578 green
254 blue
253 red
253 yellow
118 orange
 etc.

My PHP looks like this so far:

$sql = select count(*) as count, searchkeywords from searchtable  
group by searchkeywords order by count desc;
$result = @mysql_query($sql,$connection) or die(Couldn't execute  
checkcat query);

$num = mysql_num_rows($result);
echo $num;


The echo is of course returning the total number of records not  
data as listed above.


I know a WHILE statement is to be used here, but can't get it to work.

How do I loop through the above found data, inserting each value as  
like this:


insert into mytable (count, color) values (578, green);
insert into mytable (count, color) values (254, blue);
...etc



Thanks,


 --Rick


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



Re: [PHP] PHP loop to issue sql insert

2010-11-14 Thread Rick Dwyer


On Nov 14, 2010, at 8:15 PM, Simon J Welsh wrote:


On 15/11/2010, at 12:47 PM, Rick Dwyer wrote:


Hello List.

I have a sql command that counts, groups and sorts data from a  
table.  I need to insert the results of that sql command into  
different table.


My sql SELECT looks like  this:

select count(*) as count, searchkeywords from searchtable group by  
searchkeywords order by count desc;


and returns records like this:

578 green
254 blue
253 red
253 yellow
118 orange
 etc.

My PHP looks like this so far:

$sql = select count(*) as count, searchkeywords from searchtable  
group by searchkeywords order by count desc;
$result = @mysql_query($sql,$connection) or die(Couldn't execute  
checkcat query);

$num = mysql_num_rows($result);
echo $num;


The echo is of course returning the total number of records not  
data as listed above.


I know a WHILE statement is to be used here, but can't get it to  
work.


How do I loop through the above found data, inserting each value as  
like this:


insert into mytable (count, color) values (578, green);
insert into mytable (count, color) values (254, blue);
...etc



Thanks,


--Rick


Personally I'll get MySQL to do it for me using: insert into mytable  
(count, color) select count(*) as count, searchkeywords from  
searchtable group by searchkeywords order by count desc (see http://dev.mysql.com/doc/refman/5.1/en/insert-select.html 
 for more information on INSERT ... SELECT)


Wow... I have never heard of the combination of INSERT... SELECT  
before worked perfectly.  Thanks.


--Rick


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



Re: [PHP] Auto-generating HTML

2010-09-20 Thread Rick Pasotto
On Mon, Sep 20, 2010 at 03:02:35PM -0400, TR Shaw wrote:
 
 On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote:
 
  Hey folks,
  
   I have the feeling this is a stupid question, but I can't even find
  anything about it.  Maybe I'm just not searching for the right things.
  
   Here's the problem.  I'm writing a lot of pages, and I hate going in
  and out of PHP.  At the same time, I want my HTML to be legible.  When
  you look at it, that's kind of a problem, though... for instance
  (assume this had some PHP in the middle, and there was actually a
  reason not to just put this in HTML in the first place):
  
  Simple PHP:
  ?php
  
  echo 'html';
  echo 'head';
  echo '  titlePage Title/title';
  echo '/head';
  echo 'body';
  echo 'pThis is the page body/p';
  echo '/body';
  echo '/html';
  
  ?
  
  
  Output page source:
  htmlhead  titlePage Title/title/headbodypThis is the
  page body/p/body/html
  
  
  Now, I can go through and add a newline to the end of each line (echo
  'html' . \n; and so on), but it adds a lot of typing.  Is there a
  way to make this happen automatically?  I thought about just building
  a simple function, but I run into problem with quotes -- either I
  can't use single quotes, or I can't use double quotes.  Historically,
  I've dealt with the issue by just having ugly output code, but I'd
  like to stop doing that.  How do other people deal with this?
  
  Thanks,
   Alex
 
 Alex
 
 Just add a \n at the end as
 
 echo 'html\n';

That will not work. Single quotes means that the '\n' is not interpreted
as a new line so you'll see a bunch of '\n' in the output.

What I sometimes do is:

$out = array();
$out[] = 'html';
$out[] = 'head';
$out[] = '  titlePage Title/title';
$out[] = '/head';
$out[] = 'body';
$out[] = 'pThis is the page body/p';
$out[] = '/body';
$out[] = '/html';
echo join(\n,$out);

-- 
Act as if you were already happy and that will tend to make you happy.
-- Dale Carnegie
Rick Pasottor...@niof.nethttp://www.niof.net

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



[PHP] strtotime()

2010-08-23 Thread Rick Pasotto
On my home machine running 5.3.2-2 in debian linux the commands:

echo date('Y-m-d',strtotime('first day of this month')).'br/';
echo date('Y-m-d',strtotime('last day of next month'));

give the expected results.

I just got setup with a hosting provider running 5.2.13 on BSD and both
give '1969-12-31'.

What could be causing this? The second command is straight from the
manual and the first is clearly implied.

So far everything else seems to work as expected.

-- 
Economics is extremely useful as a form of employment for economists.
-- John Kenneth Galbraith
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] strtotime()

2010-08-23 Thread Rick Pasotto
On Mon, Aug 23, 2010 at 05:57:28PM -0400, Daniel Brown wrote:
 On Mon, Aug 23, 2010 at 17:02, Ashley Sheridan a...@ashleysheridan.co.uk 
 wrote:
 
  The example you quote as being straight from the manual page is actually
  from the user-submitted code snippets, and I can't find the
  documentation to support it. I can only assume that it's possibly an
  experimental thing, or something that shouldn't work but by freak
  coincidence does occasionally. Maybe use mktime() instead to get the
  dates?
 
 Relative date strings - specifically including those terms - are
 in PHP5 = 5.3.0 exclusively, for now.  I don't believe there are any
 plans to backport it to the 5.2 branch.
 
 Rick, if you want to add this as a Documentation Problem to
 http://bugs.php.net/, one of us will likely add it to the
 documentation, as it probably should not only be noted, but also be in
 an easy-to-find place (you know, such as right there on the
 strtotime() manual entry).

After I sent my original post the one and only user comment on the
relative date strings man page was pointed out to me. So, it's there but
how many people make a habit of reading all the user comments?

Anyway, the following work:

// first day of this month
$t1 = strtotime(date('Y-m',strtotime('this month')));

// last day of next month
// get the first day of month after next and subtract one day
$t2 = strtotime(date('Y-m',$t1 + (86400 * 70)))-86400;

-- 
I'm so optimistic I'd go after Moby Dick in a row boat and take the
 tartar sauce with me. -- Zig Zigler
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] strtotime()

2010-08-23 Thread Rick Pasotto
On Mon, Aug 23, 2010 at 11:38:41PM -0400, Daniel P. Brown wrote:
 On Mon, Aug 23, 2010 at 22:27, Rick Pasotto r...@niof.net wrote:
 
  After I sent my original post the one and only user comment on the
  relative date strings man page was pointed out to me. So, it's there but
  how many people make a habit of reading all the user comments?
 
 A few thousand per day, give or take.
 
 I do remember seeing which page had the note, but I don't recall
 which one.  Can you send me the link so that I can pop that out and
 put the info in the documentation?

http://us2.php.net/manual/en/datetime.formats.relative.php

-- 
There are always three speeches, for every one you actually gave. The
 one you practiced, the one you gave, and the one you wish you gave.
-- Dale Carnegie
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] Quotes vs. Single Quote

2010-08-05 Thread Rick Dwyer

On Aug 5, 2010, at 10:43 PM, Michael Shadle wrote:

 On Thu, Aug 5, 2010 at 7:10 PM, Rick Dwyer rpdw...@earthlink.net wrote:
 Hi List.
 I've mentioned before that I am both just beginning to learn PHP AND I have 
 inherited a number of pages that I'm trying to clean up the w3c validation 
 on.
 
 Something that confuses me is how the code on the page is written where in 
 one instance, it follows this:
 
 echo table border='1'tr
 
 And elsewhere on the page it follows:
 
 echo 'table border=1tr
 
 In what I've read and from many of the suggestions from this board, the 
 latter seems to be the better way to code, generally speaking.
 
 So given that the page has javascript in it, perhaps the reason for the 
 previous developer switching between the two was for ease of incorporating 
 JS? Don't really know... but what I would like to know is it considered 
 poor coding switch between the two on a single page or is it perfectly 
 acceptable?
 
 2nd question, in the 3 lines below:
 
 $_SESSION['newpage'] = $newpage;
 $checkstat = select field from table where fieldid = $field_id;
 $result1 = @mysql_query($checkstat,$connection) or die(Couldn't execute 
 query);
 
 You could always do:
 
 $result1 = mysql_query(SELECT field FROM table WHERE fieldid =
 $field_id, $connection) or die(Couldn't execute query);
 
 a) I capped SQL verbs. Make it more readable :)
 b) why make a variable just to throw it in the next line?
 c) Make sure $field_id is truly an integer. If not, intval,
 mysql_escape_string, something along those lines. Also put it in
 single quotes if not an integer.
 d) I left double quotes in the error, because it has a single quote
 inside of it. The small micro-optimization performance you might get
 is probably not worth the readability factor.
 
 My general rules of thumb:
 
 I use double quotes if:
 a) I have single quotes inside the string
 b) I need variables to be parsed
 c) I need control characters like \n parsed
 
 I use single quotes always:
 a) For array indexes $foo['bar']
 b) If I don't need variable parsing, control characters, etc. why not?
 
 You'll get a minimal performance gain by using single quotes
 everywhere in PHP where you don't -need- double quotes, but that's a
 micro-optimization and there's probably more important things for you
 to be doing.
 
 For HTML, -always- use double quotes.
 
 tag attribute=bar / is the right way.
 tag attribute='bar' / is the wrong way.
 
 I'd go into more explanation but there simply doesn't need to be one.

Michael:

Well put.. exactly the type of instruction I was looking for.

Thanks,
--Rick







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



[PHP] Encoding for W3C Validation

2010-08-03 Thread Rick Dwyer
Hello List.

In the Alt section of the IMG tag below, the variable $myitem has a value of 
Who's There.

echo div class='myclass'a href='#' class='color_thumb' img 
src='/itemimages/$mypic' alt='$myitem' width='60' 

When running through W3C validator, the line errors out because of the  '  in 
Who's.
I tried:
$myitem=(htmlentities($myitem));

But this has no affect on Who's.

What's the best way to code this portion so the apostrophe is handled correctly?


TIA,

--Rick




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



Re: [PHP] Encoding for W3C Validation

2010-08-03 Thread Rick Dwyer

On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:

 Rick Dwyer wrote:
 Hello List.
 
 In the Alt section of the IMG tag below, the variable $myitem has a value of 
 Who's There.
 
 echo div class='myclass'a href='#' class='color_thumb' img 
 src='/itemimages/$mypic' alt='$myitem' width='60' 
 
 When running through W3C validator, the line errors out because of the  '  
 in Who's.
 I tried:
 $myitem=(htmlentities($myitem));
 
 But this has no affect on Who's.
 
 What's the best way to code this portion so the apostrophe is handled 
 correctly?
 
 
 TIA,
 
 --Rick
 
 
 
 
 Use it
 
 
 echo 'div class=myclassa href=# class=color_thumb img
 src=/itemimages/'.$mypic.' alt='.$myitem.' width=60 ...'


Thanks Sebastian.

In the above, what is the function of the period in front of $myitem?

--Rick


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



Re: [PHP] Encoding for W3C Validation

2010-08-03 Thread Rick Dwyer
Thanks Ash... this worked.

--Rick

On Aug 3, 2010, at 3:01 PM, Ashley Sheridan wrote:

 On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:
 
 On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
 
 Rick Dwyer wrote:
 Hello List.
 
 In the Alt section of the IMG tag below, the variable $myitem has a value 
 of Who's There.
 
 echo div class='myclass'a href='#' class='color_thumb' img 
 src='/itemimages/$mypic' alt='$myitem' width='60' 
 
 When running through W3C validator, the line errors out because of the  ' 
  in Who's.
 I tried:
 $myitem=(htmlentities($myitem));
 
 But this has no affect on Who's.
 
 What's the best way to code this portion so the apostrophe is handled 
 correctly?
 
 
 TIA,
 
 --Rick
 
 
 
 
 Use it
 
 
 echo 'div class=myclassa href=# class=color_thumb img
 src=/itemimages/'.$mypic.' alt='.$myitem.' width=60 ...'
 
 
 Thanks Sebastian.
 
 In the above, what is the function of the period in front of $myitem?
 
 --Rick
 
 
 
 
 It is a string concatenation in PHP. But, as my last email on this
 thread shows, you only need to add ENT_QUOTES to your htmlentities()
 call and everything will work.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 


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



Re: [PHP] Encoding for W3C Validation

2010-08-03 Thread Rick Dwyer

On Aug 3, 2010, at 3:15 PM, Sebastian Ewert wrote:

 Ashley Sheridan wrote:
 On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:
 
 On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
 
 Rick Dwyer wrote:
 Hello List.
 
 In the Alt section of the IMG tag below, the variable $myitem has a value 
 of Who's There.
 
 echo div class='myclass'a href='#' class='color_thumb' img 
 src='/itemimages/$mypic' alt='$myitem' width='60' 
 
 When running through W3C validator, the line errors out because of the  
 '  in Who's.
 I tried:
 $myitem=(htmlentities($myitem));
 
 But this has no affect on Who's.
 
 What's the best way to code this portion so the apostrophe is handled 
 correctly?
 
 
 TIA,
 
 --Rick
 
 
 
 
 Use it
 
 
 echo 'div class=myclassa href=# class=color_thumb img
 src=/itemimages/'.$mypic.' alt='.$myitem.' width=60 ...'
 
 Thanks Sebastian.
 
 In the above, what is the function of the period in front of $myitem?
 
 --Rick
 
 
 
 
 It is a string concatenation in PHP. But, as my last email on this
 thread shows, you only need to add ENT_QUOTES to your htmlentities()
 call and everything will work.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 
 
 
 If you use single quotes you can't use variables inside the string. You
 have to combine strings and variables or two strings with a dot.
 
 echo 'foo'.$bar;
 
 http://www.php.net/manual/de/language.types.string.php
 
 I'm not shure but I think to validate xhtml you need the double quotes.

Problem I'm having is I've inherited a PHP page that contains sections of 
PHP/Javascript/HTML/CSS all inside of a PHP echo tag.  My PHP and JS skill are 
rudimentary at best so when it comes to a block of code 40 to 50 lines in 
length, it becomes daunting to reverse the ' with .  Each echo block starts 
with a  and the html inside uses a '.  JS also uses '.

Below is an actual block in more detail with JS in it.  Is it still recommended 
to switch with  with ' and ' with ?

--Rick


  echo 
  pClick on a picture to view that color:/p;
  If (trim($pic_1)  ) {echo div class='proddetailpics'a href='#' 
class='color_thumb' img src='/imagedir/$pic_1' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_1',0) border='0' 
//a/div;}
  If (trim($pic_2)  ) {echo div class='proddetailpics'a href='#' 
class='color_thumb' img src='/imagedir/$pic_2' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_2',0) border='0' 
//a/div;}
  If (trim($pic_3)  ) {echo div class='proddetailpics'a href='#' 
class='color_thumb' img src='/imagedir/$pic_3' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_3',0) border='0' 
//a/div;}   
  If (trim($pic_4)  ) {echo div class='proddetailpics'a href='#' 
class='color_thumb' img src='/imagedir/$pic_4' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_4',0) border='0' 
//a/div;}   
  If (trim($pic_5)  ) {echo div class='proddetailpics'a href='#' 
class='color_thumb' img src='/imagedir/$pic_5' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_5',0) border='0' 
//a/div;}  
  If (trim($pic_6)  ) {echo div class='proddetailpics'a href='#' 
class='color_thumb' img src='/imagedir/$pic_6' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_6',0) border='0' 
//a/div;}  
  If (trim($pic_7)  ) {echo div class='proddetailpics'a href='#' 
class='color_thumb' img src='/imagedir/$pic_7' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_7',0) border='0' 
//a/div;}  
  If (trim($pic_8)  ) {echo div class='proddetailpics'a href='#' 
class='color_thumb' img src='/imagedir/$pic_8' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_8',0) border='0' 
//a/div;}  
  }


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



Re: [PHP] Encoding for W3C Validation

2010-08-03 Thread Rick Dwyer

On Aug 3, 2010, at 3:36 PM, Ashley Sheridan wrote:

 On Tue, 2010-08-03 at 15:32 -0400, Rick Dwyer wrote:
 
 On Aug 3, 2010, at 3:15 PM, Sebastian Ewert wrote:
 
  Ashley Sheridan wrote:
  On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:
  
  On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
  
  Rick Dwyer wrote:
  Hello List.
  
  In the Alt section of the IMG tag below, the variable $myitem has a 
  value of Who's There.
  
  echo div class='myclass'a href='#' class='color_thumb' img 
  src='/itemimages/$mypic' alt='$myitem' width='60' 
  
  When running through W3C validator, the line errors out because of the 
   '  in Who's.
  I tried:
  $myitem=(htmlentities($myitem));
  
  But this has no affect on Who's.
  
  What's the best way to code this portion so the apostrophe is handled 
  correctly?
  
  
  TIA,
  
  --Rick
  
  
  
  
  Use it
  
  
  echo 'div class=myclassa href=# class=color_thumb img
  src=/itemimages/'.$mypic.' alt='.$myitem.' width=60 ...'
  
  Thanks Sebastian.
  
  In the above, what is the function of the period in front of $myitem?
  
  --Rick
  
  
  
  
  It is a string concatenation in PHP. But, as my last email on this
  thread shows, you only need to add ENT_QUOTES to your htmlentities()
  call and everything will work.
  
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
  
  
  
  
  
  If you use single quotes you can't use variables inside the string. You
  have to combine strings and variables or two strings with a dot.
  
  echo 'foo'.$bar;
  
  http://www.php.net/manual/de/language.types.string.php
  
  I'm not shure but I think to validate xhtml you need the double quotes.
 
 Problem I'm having is I've inherited a PHP page that contains sections of 
 PHP/Javascript/HTML/CSS all inside of a PHP echo tag.  My PHP and JS skill 
 are rudimentary at best so when it comes to a block of code 40 to 50 lines 
 in length, it becomes daunting to reverse the ' with .  Each echo block 
 starts with a  and the html inside uses a '.  JS also uses '.
 
 Below is an actual block in more detail with JS in it.  Is it still 
 recommended to switch with  with ' and ' with ?
 
 --Rick
 
 
echo 
pClick on a picture to view that color:/p;
   If (trim($pic_1)  ) {echo div class='proddetailpics'a href='#' 
 class='color_thumb' img src='/imagedir/$pic_1' alt='$itemgroup 
 $itemsubgroup' width='60' height='60' 
 onclick=MM_swapImage('prodimage','','/imagedir/$pic_1',0) border='0' 
 //a/div;}
   If (trim($pic_2)  ) {echo div class='proddetailpics'a href='#' 
 class='color_thumb' img src='/imagedir/$pic_2' alt='$itemgroup 
 $itemsubgroup' width='60' height='60' 
 onclick=MM_swapImage('prodimage','','/imagedir/$pic_2',0) border='0' 
 //a/div;} 
   If (trim($pic_3)  ) {echo div class='proddetailpics'a href='#' 
 class='color_thumb' img src='/imagedir/$pic_3' alt='$itemgroup 
 $itemsubgroup' width='60' height='60' 
 onclick=MM_swapImage('prodimage','','/imagedir/$pic_3',0) border='0' 
 //a/div;}
   If (trim($pic_4)  ) {echo div class='proddetailpics'a href='#' 
 class='color_thumb' img src='/imagedir/$pic_4' alt='$itemgroup 
 $itemsubgroup' width='60' height='60' 
 onclick=MM_swapImage('prodimage','','/imagedir/$pic_4',0) border='0' 
 //a/div;}
   If (trim($pic_5)  ) {echo div class='proddetailpics'a href='#' 
 class='color_thumb' img src='/imagedir/$pic_5' alt='$itemgroup 
 $itemsubgroup' width='60' height='60' 
 onclick=MM_swapImage('prodimage','','/imagedir/$pic_5',0) border='0' 
 //a/div;}   
   If (trim($pic_6)  ) {echo div class='proddetailpics'a href='#' 
 class='color_thumb' img src='/imagedir/$pic_6' alt='$itemgroup 
 $itemsubgroup' width='60' height='60' 
 onclick=MM_swapImage('prodimage','','/imagedir/$pic_6',0) border='0' 
 //a/div;}   
   If (trim($pic_7)  ) {echo div class='proddetailpics'a href='#' 
 class='color_thumb' img src='/imagedir/$pic_7' alt='$itemgroup 
 $itemsubgroup' width='60' height='60' 
 onclick=MM_swapImage('prodimage','','/imagedir/$pic_7',0) border='0' 
 //a/div;}   
   If (trim($pic_8)  ) {echo div class='proddetailpics'a href='#' 
 class='color_thumb' img src='/imagedir/$pic_8' alt='$itemgroup 
 $itemsubgroup' width='60' height='60' 
 onclick=MM_swapImage('prodimage','','/imagedir/$pic_8',0) border='0' 
 //a/div;}   
}
 
 
 
 That's some damn ugly code that I'd consider putting in a loop right away!

The whole page is like this that's why I said it was daunting : (

[PHP] Encoding Ampersands

2010-07-28 Thread Rick Dwyer
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



Re: [PHP] Encoding Ampersands

2010-07-28 Thread Rick Dwyer
So htmlentities() will work for Green, Red  Blue?

Will it work for htm?color=bluenumber=2letter=?

--Rick





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
 
 


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



Re: [PHP] Encoding Ampersands

2010-07-28 Thread Rick Dwyer
Exactly what I was looking for!

Thanks Josh.

--Rick

On Jul 29, 2010, at 12:33 AM, Josh Kehn wrote:

 Rick-
 
 Give it a try!
 
 ?php
 $test_one = Green, Red  Blue;
 $test_two = htm?color=bluenumber=2letter=a;
 
 echo htmlentities($test_one); // Green, Red amp; Blue
 echo htmlentities($test_two); // htm?color=blueamp;number=2amp;letter=a
 
 ?
 
 Regards,
 
 -Josh
 
 On Jul 29, 2010, at 12:29 AM, Rick Dwyer wrote:
 
 So htmlentities() will work for Green, Red  Blue?
 
 Will it work for htm?color=bluenumber=2letter=?
 
 --Rick
 
 
 
 
 
 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
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


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



[PHP] PHP Pill

2010-07-17 Thread Rick Dwyer

Hello all.

I inquired about the problem below on a FM board but no one could  
help.  Hoping someone here may have an explanation or a workaround.


I have PHP Pill installed on both a Mac and PC versions of FileMaker  
11. On the Mac, things behave as expected. On the PC, they do not. My  
code is below:


$old_string= 'Antique Houses™ Appointment Calendar';
$find = '/[^a-z0-9]/i';
$replace = '';
$new_string = preg_replace($find, $replace, $old_string);
$new_string = trim($new_string, );
echo $new_string;

So on the Mac, the above returns:
AntiqueHousesAppointmentCalendar

vs. the PC returns:
AntiqueHousesTAppointmentCalendar

Is there any reason the PC version of FM converts the TM symbol to a T  
instead of removing as it should via regex?

Thanks.


--Rick



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



Re: [PHP] PHP Pill

2010-07-17 Thread Rick Dwyer

Hi Ash.

Yes, windows XP, I believe.  PHP Pill is a FileMaker plugin that  
allows you to execute PHP from within your FM code.  What I don't  
understand is that the PHP regex should be removing ALL items not in  
my regex list... it does so in FM on the Mac but not on the PC.  But  
the plugin is working as it is removing everthing... but gets tripped  
on the trade mark symbol.  I sent a side by side screen shot of the  
fields on the mac and pc to your personal address.




 --Rick


On Jul 17, 2010, at 12:34 PM, Ashley Sheridan wrote:


On Sat, 2010-07-17 at 12:30 -0400, Rick Dwyer wrote:


Hello all.

I inquired about the problem below on a FM board but no one could
help.  Hoping someone here may have an explanation or a workaround.

I have PHP Pill installed on both a Mac and PC versions of FileMaker
11. On the Mac, things behave as expected. On the PC, they do not. My
code is below:

$old_string= 'Antique Houses™ Appointment Calendar';
$find = '/[^a-z0-9]/i';
$replace = '';
$new_string = preg_replace($find, $replace, $old_string);
$new_string = trim($new_string, );
echo $new_string;

So on the Mac, the above returns:
AntiqueHousesAppointmentCalendar

vs. the PC returns:
AntiqueHousesTAppointmentCalendar

Is there any reason the PC version of FM converts the TM symbol to  
a T

instead of removing as it should via regex?
Thanks.


--Rick





It sounds like somewhere along the line the character format isn't  
being observed. I'm not sure what PHP Pill is, and a quick Google  
for it brought up some odd results which didn't look like software!  
What happens when you output the string length on each system? I'm  
assuming you're using Windows on the PC, and not Linux, as that is  
where I've seen most issues with character encoding in the past.


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






Re: [PHP] PHP Pill

2010-07-17 Thread Rick Dwyer



On Jul 17, 2010, at 1:29 PM, Ashley Sheridan wrote:





Well, I did suggest one thing that could be happening. What do both
string lengths come to?



On the PC, the length of variable old string is 44 and new string is 39
On the Mac, the length of varialbe old string is 44 and new string is  
38.


This is all happening inside of FileMaker... I will test the PHP code  
inside a web browser on both plaforms to see what happens.


--Rick








Re: [PHP] PHP Pill

2010-07-17 Thread Rick Dwyer


On Jul 17, 2010, at 2:08 PM, Rick Dwyer wrote:




On Jul 17, 2010, at 1:29 PM, Ashley Sheridan wrote:





Well, I did suggest one thing that could be happening. What do both
string lengths come to?



On the PC, the length of variable old string is 44 and new string is  
39
On the Mac, the length of varialbe old string is 44 and new string  
is 38.


This is all happening inside of FileMaker... I will test the PHP  
code inside a web browser on both plaforms to see what happens.




OK to further bolster my assumption that this is a Scodigo/FM issue,  
the PHP code outputs identical string lengths to web browsers on both  
Mac and PC and both output the string correctly.

Only in FM on the PC does this occur.

 sure wish Scodigo would reply

--Rick

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



Re: [PHP] PHP Pill

2010-07-17 Thread Rick Dwyer


On Jul 17, 2010, at 2:34 PM, Peter Lind wrote:


On 17 July 2010 20:08, Rick Dwyer rpdw...@earthlink.net wrote:



On Jul 17, 2010, at 1:29 PM, Ashley Sheridan wrote:





Well, I did suggest one thing that could be happening. What do both
string lengths come to?



On the PC, the length of variable old string is 44 and new string  
is 39
On the Mac, the length of varialbe old string is 44 and new string  
is 38.


This is all happening inside of FileMaker... I will test the PHP  
code inside

a web browser on both plaforms to see what happens.

--Rick



Windows uses two characters for newlines, mac uses one. Just a guess.

Regards
Peter

Thanks Peter, but while this may explain the character length  
difference, it doesn't explain the Trademark symbol.  I really  
beginning to believe that Scodigo, the manufacturer of PHP Pill is  
going to have to resolve this one.


--Rick


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



Re: [PHP] HTML in emails

2010-07-04 Thread Rick Pasotto
On Sun, Jul 04, 2010 at 06:31:38PM +0200, Per Jessen wrote:
 Al wrote:
 
  I know this is a bit off-topic; but close enough.
  
  I'm starting to update the email feature of one of my DB applications
  and noticed that it appears most of the fancy emails I receive are
  using just plain old, simple html pages, with a note about not being
  able to see, go here with a link.

Such emails are stupid. Obviously I can read the email quite fine. The
problem is that there is no useful content. Just an instruction to click
on a link.

  It use to be that we specified content-type text/html, etc. and sent
  both the plain ASCII and the html with boundaries and so forth.
 
 Yes, multipart/alternative that was. 
 
  Seems like, from my preliminary Google searching, I should not waste
  time with the standard's way and just go straight to sending simple
  html pages since all modern browsers handle it well. 
  And, it appears to be the way web is going.

Then I will never read your email.

Browsers are for web pages, not email.

  What are you folks doing?
 
 We follow the standard and send both text and html. 

The text portion is the *only* portion I read.

-- 
When dealing with people, remember you are not dealing with creatures
 of logic, but creatures of emotion. -- Dale Carnegie
Rick Pasottor...@niof.nethttp://www.niof.net

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



[PHP] Stripping Characters

2010-06-22 Thread Rick Dwyer

Hello List.

I need to remove characters from a string and replace them with and  
underscore.


So instead of having something like:

$moditem = str_replace(--,_,$mystring);
$moditem = str_replace(?,_,$mystring);
$moditem = str_replace(!,_,$mystring);
etc.

For every possible character I can think of, is there a way to simply  
omit any character that is not an alpha character and not a number  
value from 0 to 9?



 --Rick



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



Re: [PHP] Stripping Characters

2010-06-22 Thread Rick Dwyer

Thanks to everyone who responded.

Regarding the myriad of choices, isn't Ashley's, listed below, the one  
most like to guarantee the cleanest output of just letters and numbers?



 --Rick


On Jun 22, 2010, at 11:44 AM, Ashley Sheridan wrote:


On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote:
Use preg_replace(), which allows you to use a regex to specify what  
you want to match:


$find = '/[^a-z0-9]/i';
$replace = '_';
$new_string = preg_replace($find, $replace, $old_string);

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






Re: [PHP] Stripping Characters

2010-06-22 Thread Rick Dwyer

Hello again list.

My code for stripping characters is below.  I'm hoping to get feedback  
as to how rock solid it will provide the desired output under any  
circumstance:


My output must look like this (no quotes):

This-is-my-string-with-lots-of-junk-characters-in-it

The code with string looks like this:

$old_string = 'This is my   $string -- with ƒ  
lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®† 
¥¨ˆøπ“‘ååß∂ƒ©˙∆˚¬…æ`__';


$find = '/[^a-z0-9]/i';
$replace = ' ';

$new_string = preg_replace($find, $replace, $old_string);
$new_string = preg_replace(/ {2,}/, -, $new_string);
$new_string = preg_replace(/ {1,}/, -, $new_string);

$new_string = rtrim($new_string, -);
$new_string = ltrim($new_string, -);


echo $new_string;

Will the logic above capture and remove every non alpha numeric  
character and place a SINGLE hyphen between the non contiguous alpha  
numeric characters?


Thanks for the help on this.


 --Rick


On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote:




On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote:


It is clean, but as Richard mentioned, it won't handle strings  
outside of the traditional 128 ASCII range, so accented characters  
and the like will be converted to an underscore. Also, spaces might  
become an issue.


However, if you are happy that your input won't go beyond the a- 
z0-9 range, then it should do what you need.


No, actually I'm fairly confident characters outside the 128 range  
are what are causing me problems now.


So I will try Richard's method.

Thanks to all.

--Rick




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



Re: [PHP] Stripping Characters

2010-06-22 Thread Rick Dwyer

Very good.
Thank you.

 --Rick


On Jun 22, 2010, at 8:14 PM, Ashley Sheridan wrote:


On Tue, 2010-06-22 at 20:03 -0400, Rick Dwyer wrote:


Hello again list.

My code for stripping characters is below.  I'm hoping to get  
feedback

as to how rock solid it will provide the desired output under any
circumstance:

My output must look like this (no quotes):

This-is-my-string-with-lots-of-junk-characters-in-it

The code with string looks like this:

$old_string = 'This is my   $string -- with ƒ
lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®†
¥¨ˆøπ“‘ååß∂ƒ©˙∆˚¬… 
æ`__';


$find = '/[^a-z0-9]/i';
$replace = ' ';

$new_string = preg_replace($find, $replace, $old_string);
$new_string = preg_replace(/ {2,}/, -, $new_string);
$new_string = preg_replace(/ {1,}/, -, $new_string);

$new_string = rtrim($new_string, -);
$new_string = ltrim($new_string, -);


echo $new_string;

Will the logic above capture and remove every non alpha numeric
character and place a SINGLE hyphen between the non contiguous alpha
numeric characters?

Thanks for the help on this.


  --Rick


On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote:



 On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote:

 It is clean, but as Richard mentioned, it won't handle strings
 outside of the traditional 128 ASCII range, so accented characters
 and the like will be converted to an underscore. Also, spaces  
might

 become an issue.

 However, if you are happy that your input won't go beyond the a-
 z0-9 range, then it should do what you need.

 No, actually I'm fairly confident characters outside the 128 range
 are what are causing me problems now.

 So I will try Richard's method.

 Thanks to all.

 --Rick





You can remove the second line of code, as the third one is  
replacing what line 2 does anyway.


Also, instead of a rtrim and ltrim, you can merge the two with a  
single call to trim, which will work on both ends of the string at  
once.


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






[PHP] function within a class function

2010-06-20 Thread Rick Pasotto
Within a class function I have defined another function for use with the
usort() function. How do I reference it?

When it's not part of a class usort($arr,cmp) works fine but when it's
within a class function I get this error:

PHP Parse error:  syntax error, unexpected T_STRING, expecting T_FUNCTION

Is it not in the scope of the class function?

-- 
Memory is like an orgasm.  It's a lot better if you don't have to fake it.
-- Seymour Cray (on virtual memory)
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] function within a class function

2010-06-20 Thread Rick Pasotto
On Sun, Jun 20, 2010 at 08:47:53PM -0400, Brandon Rampersad wrote:
 $this-usort();
 self::usort();
 
 On Sun, Jun 20, 2010 at 7:45 PM, Rick Pasotto r...@niof.net wrote:
 
  Within a class function I have defined another function for use with the
  usort() function. How do I reference it?
 
  When it's not part of a class usort($arr,cmp) works fine but when it's
  within a class function I get this error:
 
  PHP Parse error:  syntax error, unexpected T_STRING, expecting T_FUNCTION
 
  Is it not in the scope of the class function?

Forgive my ignorance but I have absolutely no idea what you're trying to
tell me.

usort() is part of the language so when, why, how does it become an
object of some class?

-- 
We have rights, as individuals, to give as much of our own money as
 we please to charity; but as members of Congress we have no right so
 to appropriate a dollar of public money. -- David Crockett
Rick Pasottor...@niof.nethttp://www.niof.net

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



[PHP] not receiving mail from list

2010-06-20 Thread Rick Pasotto
This evening I sent two emails to the list but have not received either
of them back. Checking my logs I see that the last email I got was dated
2010-06-12. Could I have been unsubscribed without my knowing about it?

(My posts were received by the list since I got private replies.)

-- 
...He who laughs does not believe in what he laughs at, but neither does
 he hate it. Therefore, laughing at evil means not preparing oneself to
 combat it, and laughing at good means denying the power through which
 good is self-propagating. -- Umberto Eco, The Name of the Rose
Rick Pasottor...@niof.nethttp://www.niof.net

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



[PHP] What am I missing here?

2010-06-19 Thread Rick Dwyer

Hello List.

I am completely at a loss for why the line of code below returns the  
desired value:


$PATH_INFO= substr($_SERVER['REQUEST_URI'],strlen($_SERVER['SCRI
PT_NAME']), strlen($_SERVER['REQUEST_URI']));

BUT, putting the same line of code on 1 line fails to return anything:

$PATH_INFO=  
substr($_SERVER['REQUEST_URI'],strlen($_SERVER['SCRIPT_NAME']),  
strlen($_SERVER['REQUEST_URI']));




 --Rick



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



[PHP] Replacing Registered Symbol

2010-06-18 Thread Rick Dwyer

Hello List.

I'm trying to replace the registered (®) symbol from a variable via PHP.

The variable $mystring is set to a MySQL field that contains the value  
This Is The Registered Symbol ®.


Using the following, I try to replace the symbol, but it persists:

$moditem = str_replace(®,,$mystring);

I tried replacing the symbol in the above syntax with the HTML  
equivalent but no luck.


Any help is appreciated.

Thanks,

 --Rick



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



Re: [PHP] newbie sequel question: how do we search for multiple things on 1 field like:

2010-06-18 Thread Rick Dwyer
SELECT * FROM contacts WHERE state = 'CA' and (name = 'bob' or name =  
'sam' or name = 'sara')


 --Rick


On Jun 18, 2010, at 4:30 PM, Dave wrote:


SELECT * FROM contacts WHERE state = 'CA' and   name = 'bob' or
name = 'sam' or name = 'sara' 

--
Thanks - Dave

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




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



Re: [PHP] Replacing Registered Symbol

2010-06-18 Thread Rick Dwyer


On Jun 18, 2010, at 4:52 PM, Daniel Brown wrote:




   Check your database's character encoding.  My check:



Navicat shows it as Latin1.  I believe UTF-8 is what it should be, but  
I don't want to change it without understanding what impact it will  
have.



 Note that, while it won't make a
difference in your result here, you don't need to use quotes around
your variable in the str_replace() call you showed.  In fact, not only
would it slow down the processes on more-involved or more-popular
sites, but it'll have a larger impact, as you're using double quotes,
which are first evaluated, then passed.  Single quotes would, of
course, literally echo $mystring in your case, but you get the point.
Just a quick tip.


Did not know, thanks.

Re: [PHP] Replacing Registered Symbol

2010-06-18 Thread Rick Dwyer


On Jun 18, 2010, at 5:13 PM, Daniel Brown wrote:



   Can you hit the database from the command line to see if there's a
difference in the output when you take the server and browser out of
the equation?



No, I'm on Mac OS 10.5 and apparently I don't have a MySQL client  
installed in terminal.  I've always used Navicat and never had a need  
for the terminal until now.


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



Re: [PHP] Replacing Registered Symbol

2010-06-18 Thread Rick Dwyer
OK, it's definitely an encoding issue... when I change the encoding of  
my PHP page in BBedit to Western ISO Latin 1, it replaces successfully.




 --Rick


On Jun 18, 2010, at 5:13 PM, Daniel Brown wrote:

On Fri, Jun 18, 2010 at 17:07, Rick Dwyer rpdw...@earthlink.net  
wrote:


Navicat shows it as Latin1.  I believe UTF-8 is what it should be,  
but I
don't want to change it without understanding what impact it will  
have.


   Depending on your content, it could be an issue, but probably not.
A good way to check would be to copy the table, convert the encoding,
and test it.  However, my example database with LATIN1 collation still
worked as expected here.  So that may not be the issue for you after
all.

   Can you hit the database from the command line to see if there's a
difference in the output when you take the server and browser out of
the equation?

--
/Daniel P. Brown
URGENT:
THROUGH FRIDAY, 18 JUNE ONLY: $100 OFF
YOUR FIRST MONTH, FREE CPANEL FOR LIFE
ON ANY NEW DEDICATED SERVER.  NO LIMIT!
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
We now offer SAME-DAY SETUP on a new line of servers!

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




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



[PHP] String Parse Help for novice

2010-06-13 Thread Rick Dwyer

Hello List.

I need to parse the PATH portion of URL.  I have assigned the path  
portion to a variable using the following:


$thepath = parse_url($url);


Now I need to break each portion of the path down into its own  
variable.  The problem is, the path can vary considerably as follows:


/mydirectory/mysubdirectory/anothersubdirectory/mypage.php

vs.

/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the  
variables equal the following


$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be  
dynamically assigned to a variable.


 Thanks for any help.

 --Rick



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



Re: [PHP] String Parse Help for novice

2010-06-13 Thread Rick Dwyer

OK, I get the following error:

Warning: basename() expects parameter 1 to be string, array given in

When I use the following:

$thepath = parse_url($url);
$filename = basename($thepath);

Is my variable thepath not automatically string?

 --Rick


On Jun 13, 2010, at 6:23 PM, Ashley Sheridan wrote:


On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:


Hello List.

I need to parse the PATH portion of URL.  I have assigned the path
portion to a variable using the following:

$thepath = parse_url($url);


Now I need to break each portion of the path down into its own
variable.  The problem is, the path can vary considerably as follows:

/mydirectory/mysubdirectory/anothersubdirectory/mypage.php

vs.

/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the
variables equal the following

$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be
dynamically assigned to a variable.

  Thanks for any help.

  --Rick





$filename = basename($path);
$parts = explode('/', $path);
$directories = array_pop($parts);

Now you have your directories in the $directories array and the  
filename in $filename.


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





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



Re: [PHP] String Parse Help for novice

2010-06-13 Thread Rick Dwyer

OK, sorry for any confusion.

Here is all my code:

$url = http . ((!empty($_SERVER['HTTPS'])) ? s : ) . ://. 
$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

$thepath = parse_url($url);

So, given that the URL can vary as follows:

/mydirectory/mysubdirectory/anothersubdirectory/mypage.php
vs.
/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the  
variables equal the following


$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be  
dynamically assigned to a variable.


 --Rick





On Jun 13, 2010, at 6:42 PM, Ashley Sheridan wrote:


On Sun, 2010-06-13 at 18:35 -0400, Rick Dwyer wrote:


OK, I get the following error:

Warning: basename() expects parameter 1 to be string, array given  
in


When I use the following:

$thepath = parse_url($url);
$filename = basename($thepath);

Is my variable thepath not automatically string?

 --Rick


On Jun 13, 2010, at 6:23 PM, Ashley Sheridan wrote:


On Sun, 2010-06-13 at 18:13 -0400, Rick Dwyer wrote:


Hello List.

I need to parse the PATH portion of URL.  I have assigned the path
portion to a variable using the following:

$thepath = parse_url($url);


Now I need to break each portion of the path down into its own
variable.  The problem is, the path can vary considerably as  
follows:


/mydirectory/mysubdirectory/anothersubdirectory/mypage.php

vs.

/mydirectory/mypage.php

How do I get the either of the above url paths broken out so the
variables equal the following

$dir1 = mydirectory
$dir2 = mysubdirectory
$dir3 = anothersubdirectory
$page = mypage.php

...etc... if there were 5 more subdirectories... they would be
dynamically assigned to a variable.

 Thanks for any help.

 --Rick





$filename = basename($path);
$parts = explode('/', $path);
$directories = array_pop($parts);

Now you have your directories in the $directories array and the
filename in $filename.

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








Because you've given it an array. Your original question never  
mentioned

you were using parse_url() on the original array string. parse_url()
breaks the string into its component parts, much like my explode
example.

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





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



[PHP] php-cli

2010-03-14 Thread Rick Pasotto
Has cli php changed recently?

I've got a php script (script1) that creates a php script (script2) by
opening a file and then writing to it. When I try to run it from the
command line script1 is simply copied to stdout. When I run it from the
browser it works as expected. The directory has 777 permissions so that
should not be the problem.

Any ideas?

-- 
Whatever the immediate gains and losses, the dangers to our safety
arising from political suppression are always greater than the dangers
to that safety resulting from political freedom. Suppression is always
foolish. Freedom is always wise. -- Alexander Meiklejohn, 1955
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] php-cli

2010-03-14 Thread Rick Pasotto
On Sun, Mar 14, 2010 at 06:13:24PM +, Ashley Sheridan wrote:
 On Sun, 2010-03-14 at 14:15 -0400, Rick Pasotto wrote:
 
  Has cli php changed recently?
  
  I've got a php script (script1) that creates a php script (script2) by
  opening a file and then writing to it. When I try to run it from the
  command line script1 is simply copied to stdout. When I run it from the
  browser it works as expected. The directory has 777 permissions so that
  should not be the problem.
  
  Any ideas?
 
 How are you running it from the command line?

Is there more than one way? I suppose with and without the -f could
count as two ways, but the man page says without defaults to with so
they're really the same.

-- 
Remember, today is the tomorrow you worried about yesterday.
-- Dale Carnegie
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] php-cli

2010-03-14 Thread Rick Pasotto
On Sun, Mar 14, 2010 at 08:40:51PM +, Ashley Sheridan wrote:
 On Sun, 2010-03-14 at 16:41 -0400, Rick Pasotto wrote:
 
  On Sun, Mar 14, 2010 at 06:13:24PM +, Ashley Sheridan wrote:
   On Sun, 2010-03-14 at 14:15 -0400, Rick Pasotto wrote:
   
Has cli php changed recently?

I've got a php script (script1) that creates a php script (script2) by
opening a file and then writing to it. When I try to run it from the
command line script1 is simply copied to stdout. When I run it from the
browser it works as expected. The directory has 777 permissions so that
should not be the problem.

Any ideas?
   
   How are you running it from the command line?
  
  Is there more than one way? I suppose with and without the -f could
  count as two ways, but the man page says without defaults to with so
  they're really the same.
 
 Well you havn't given an example, and just say you're calling the script
 from command line and it's outputting the script there. Are you maybe
 just calling the php file without calling php first?

Of course not. php scripts are not executable. If I had tried to execute
it directly the shell would have told me that. If I had then set the
executable bit the shell would have tried to execute the contents of the
file and the shell would have given several error messages.

I repeat: is there more than one way to run a php script from the cli?

-- 
Feeling sorry for yourself, and you present condition, is not only a
 waste of energy but the worst habit you could possibly have.
-- Dale Carnegie
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] php-cli

2010-03-14 Thread Rick Pasotto
On Mon, Mar 15, 2010 at 01:32:24PM +1300, Dmitry Ruban wrote:
 Rick Pasotto wrote:
 
 I repeat: is there more than one way to run a php script from the cli?
 
 
 On *nix, you can add #!/usr/bin/php as first line and make file
 executable (chmod +x).

Functionally the same. php is still interpreting the script. The script
is still not an executable.

And, of course, the results are the same.

The problem is that php is *not* interpreting the script. It's acting
like 'cat'.

-- 
There are two tragedies in life.  One is to lose your heart's desire.
 The other is to gain it. -- George Bernard Shaw
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] php-cli

2010-03-14 Thread Rick Pasotto
On Mon, Mar 15, 2010 at 02:35:54PM +1300, Dmitry Ruban wrote:
 Rick Pasotto wrote:
 On Mon, Mar 15, 2010 at 01:32:24PM +1300, Dmitry Ruban wrote:
 Rick Pasotto wrote:
 I repeat: is there more than one way to run a php script from the cli?
 
 On *nix, you can add #!/usr/bin/php as first line and make file
 executable (chmod +x).
 
 Functionally the same. php is still interpreting the script. The script
 is still not an executable.
 
 And, of course, the results are the same.
 
 The problem is that php is *not* interpreting the script. It's acting
 like 'cat'.
 
 
 It sounds like you may use short tags ? and short_open_tag is off
 in your cli php.ini

Thank you. That was the problem.

Looks like I've got a habit to change and a lot of file maintenance to do.

-- 
There are two tragedies in life.  One is to lose your heart's desire.
 The other is to gain it. -- George Bernard Shaw
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] Error Message - Need help troubleshooting

2010-03-02 Thread Rick Dwyer

On Mar 2, 2010, at 12:31 AM, Rene Veerman wrote:


i doubt you passed us the entire .js.php script..


The rest of the JS is as follows:

a href='javascript:loadOSS()'img src='/images/myimage.jpg'  
width='161' height='57' align='right' /Open Window...


As far as other PHP goes, the whole page is PHP so I wouldn't know  
where to even start.  My guess was that the problem was originating  
from the previous code I sent over, but I don't know enough PHP to be  
sure.





does the script itself ever fail, asides from showing this msg?


No it works fine.  The most annoying thing in making it difficult to  
to troubleshoot is this message does not always appear.



--Rick







On Tue, Mar 2, 2010 at 5:46 AM, Rick Dwyer rpdw...@earthlink.net  
wrote:

Hello List.

I have some JS code that open a new window with a contact form in  
it.  When
the link is clicked to open the new window, I will get the  
following error

SOMETIMES:

Warning: Unknown: Your script possibly relies on a session side- 
effect
which existed until PHP 4.2.3. Please be advised that the session  
extension

does not consider global variables as a source of data, unless
register_globals is enabled. You can disable this functionality and  
this
warning by setting session.bug_compat_42 or session.bug_compat_warn  
to off,

respectively. in Unknown on line 0

My JS code with a bit of PHP in it looks like this:

function loadOSS()
var oss_itemid = ?php echo $item_id; ?;
var loadOSS = window.open(my_url/my_file.php?iid= + oss_itemid, ,
scrollbars 
= 
no 
,menubar 
= 
no 
,height 
=600,width=600,resizable=yes,toolbar=no,location=no,status=no);

}

As I said above, the error message does not always appear.

Is the error due to the fact I am JS  PHP together?

Any help in understanding what I am doing wrong is appreciated.

 --Rick



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





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



Re: [PHP] Error Message - Need help troubleshooting

2010-03-02 Thread Rick Dwyer

On Mar 2, 2010, at 8:48 AM, Ashley Sheridan wrote:


How is $item_id created? You've not shown that in your PHP script  
examples.


// parse item id from the url
$refer=$_SERVER['HTTP_REFERER'];
$thispage=$_SERVER['PHP_SELF'];
$item_id=substr($thispage, -9);
$item_id=substr($item_id, 0, 5);

$_SESSION['item_id'] = $item_id;

The above is where item_id is created and added to a session.

The important thing is that this error never showed up before until I  
added the Javascript link below:


var oss_itemid = ?php echo $item_id; ?;
var loadOSS = window.open(http://www.myurl/myfile.php?iid=; +  
oss_itemid, ,  
scrollbars 
= 
no 
,menubar 
= 
no 
,height=600,width=600,resizable=yes,toolbar=no,location=no,status=no);



When I was testing initially, I had removed the variable above in the  
link with a hard coded value and I never received this error.  Only  
when I made it dynamic did this error appear.


Thanks for any help.

--Rick

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



Re: [PHP] Error Message - Need help troubleshooting

2010-03-02 Thread Rick Dwyer


On Mar 2, 2010, at 9:35 AM, Ashley Sheridan wrote:

I'm assuming then that both the Javascript an the PHP code you have  
above are both on the same page. The only way I can see your problem  
occurring would be if your javascript part was on a different page  
and you were attempting to output the $item_id. If PHP could not  
find a variable with that name, it may be reverting to using the  
item_id value found in $_SESSION, which would give you the error  
you're seeing.



Yes this is the case.

However, what you said brings up a point if interest.  The page that  
the link is bringing up contains the following:


if ($_GET[iid]=='') {
$item_id = ($_SESSION[item_id]);
}
else
{
$item_id = $_GET[iid];
}

This code determines if the user is getting there from the initial  
link and if so, sets the variable item_id to the value passed in the  
URL.
Again however, this was not returning errors when the link was  
hardcoded with a value in place of item_id.


--Rick


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



Re: [PHP] Error Message - Need help troubleshooting

2010-03-02 Thread Rick Dwyer


On Mar 2, 2010, at 9:45 AM, Joseph Thayne wrote:

I do not know if the question has been answered, but how are you  
opening the session?  Are you using session_start() or are you using  
session_register()?


Hi Joseph.

It is created via:

session_start();

--Rick


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



[PHP] PHP Syntax Help - Check?

2010-02-24 Thread Rick Dwyer

Hello all.

I'm trying to learn PHP on the fly and I have a line of code that  
contains syntax I can't find documented anywhere:


php echo check('element8');

In the above line, can someone tell me what check means?

Thank you.

 --Rick



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



Re: [PHP] PHP Syntax Help - Check?

2010-02-24 Thread Rick Dwyer

OK... external function... that would explain why I could not locate it.

Let me get right to the problem I am having with this code as someone  
may be able to help directly.


I have a link on a page that opens a contact form.  The link is  
mypage.php?my_id=5


So on mypage.php, I capture this value with:
$my_id=$_GET['my_id'];

I understand this much.  But when the end user submits this contact  
form they do so to formcheck.php and if formcheck.php sees a required  
field is blank, it throws it back to mypage.php with an alert.  BUT, I  
lose the value of the variable $my_id.  SO, I created a hidden field  
on mypate.php with  value=?php echo $my_id; ? and on  
formcheck.php, I added $my_id = $_Post['my_id'];


However, when formcheck.php returns me to mypage.php, $my_id is still  
blank.


Very frustrating.

Any help determining what I am doing wrong is greatly appreciated.

Thanks.



 --Rick


On Feb 25, 2010, at 12:31 AM, Paul M Foster wrote:


On Thu, Feb 25, 2010 at 12:16:08AM -0500, Robert Cummings wrote:


Rick Dwyer wrote:

Hello all.

I'm trying to learn PHP on the fly and I have a line of code that
contains syntax I can't find documented anywhere:

php echo check('element8');

In the above line, can someone tell me what check means?



In the above, check is a function. It is being called with parameter
'element8'.


This is true. But perhaps more importantly, check() is not a native  
PHP

function. Thus it comes from some other library or group of external
functions.

Paul

--
Paul M. Foster

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




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



Re: [PHP] PHP Syntax Help - Check?

2010-02-24 Thread Rick Dwyer

Hmm.  OK with the help below, I am closer.

The other fields on the page are getting passed via form fields that  
look like this:


input  type=text value=?php echo check('element9'); ?  
name=form[element9] size=40 maxlength=255

so I added:
input  type=text value=?php echo check('my_id'); ?  
name=form[my_id] size=40 maxlength=255



and formcheck.php has:

?php
//start the session
session_start();

//array of fields in form. (In the format field_name = field_label)
$form_fields = array(
element0 = 'Your Name:',
element1 = 'Your Email:',
element4 = 'Item Number:',
.
);
and I added:
my_id = 'My ID Is:',

And this works!
So when I am on mypage.php and I enter a value into the form field  
my_id it carries over and repopulates should the form fail validation.


But upon initial load of the page from my link of mypage.php?my_id=5  
(so I am not getting there via a form submit) how do I get the value  
into the form field?



 --Rick


On Feb 25, 2010, at 1:02 AM, viraj wrote:


if you do the redirection with header('Location: /mypage.php'),
setting a variable on formcheck.php is not enough.

if you modify the header('Location: /mypage.php') to..

header('Location: /mypage.php?my_id=5')

it will take the variable to mypage.php as $_GET['my_id]

you can not expect a variable value set in to $_POST array to reflect
on a totally different page without making it a form post (aka use of
proper headers).

i guess, it's time to you to read about session_start() method and the
array $_SESSION available in php :)


~viraj

On Thu, Feb 25, 2010 at 11:22 AM, Rick Dwyer rpdw...@earthlink.net  
wrote:
OK... external function... that would explain why I could not  
locate it.


Let me get right to the problem I am having with this code as  
someone may be

able to help directly.

I have a link on a page that opens a contact form.  The link is
mypage.php?my_id=5

So on mypage.php, I capture this value with:
$my_id=$_GET['my_id'];

I understand this much.  But when the end user submits this contact  
form
they do so to formcheck.php and if formcheck.php sees a required  
field is
blank, it throws it back to mypage.php with an alert.  BUT, I lose  
the value
of the variable $my_id.  SO, I created a hidden field on mypate.php  
with

 value=?php echo $my_id; ? and on formcheck.php, I added $my_id =
$_Post['my_id'];

However, when formcheck.php returns me to mypage.php, $my_id is  
still blank.


Very frustrating.

Any help determining what I am doing wrong is greatly appreciated.

Thanks.



 --Rick


On Feb 25, 2010, at 12:31 AM, Paul M Foster wrote:


On Thu, Feb 25, 2010 at 12:16:08AM -0500, Robert Cummings wrote:


Rick Dwyer wrote:


Hello all.

I'm trying to learn PHP on the fly and I have a line of code that
contains syntax I can't find documented anywhere:

php echo check('element8');

In the above line, can someone tell me what check means?



In the above, check is a function. It is being called with  
parameter

'element8'.


This is true. But perhaps more importantly, check() is not a  
native PHP

function. Thus it comes from some other library or group of external
functions.

Paul

--
Paul M. Foster

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




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






--
~viraj

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




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



Re: [PHP] Formatting Decimals Further Help

2010-01-22 Thread Rick Dwyer

Hello List.

In an earlier post, I received help with a custom function to round  
decimals off (the custom function provided by Adam Richardson is below).


However in my MySQL db, when I have values with only 1 decimal point,  
I need the value PHP returns to display as 2.  For example, 3.8 needs  
to display as 3.80.


My line of code that calls the custom function looks like this:

$my_price = round_to_half_cent(number_format($my_price, 3, '.', ','));

When the value of $my_price is 3.81, it returns 3.81.  However, when  
the value of $my_price is 3.8 that is what it returns.


How can I force the formatting of my_price to always contain either 2  
or 3 decimal points (3 if the original number contains 3 or more  
decimal points to begin with)



Thanks,

--Rick



On Jan 11, 2010, at 10:39 PM, Adam Richardson wrote:

On Mon, Jan 11, 2010 at 7:45 PM, Mattias Thorslund matt...@thorslund.us 
wrote:



tedd wrote:


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

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


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

gets rounded up to full cents.

Can this be done fairly easily?  Not knowing PHP well, I am not  
aware of

the logic to configure this accordingly.

Thanks,
--Rick




--Rick:

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

rounding is not worth the effort.

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


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

In the case of 5, then look to the number that precedes it -- if  
it is
even, then round up and if it is odd, then round down -- or vise  
versa, it

doesn't make any difference as long as you are consistent.

Here are some examples:

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

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

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

PHP's rounding function is quite sufficient.

Cheers,

tedd


However that's not what Rick is asking for. He needs a function  
that rounds

to the half penny with a bias to rounding up (greedy bosses):


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

This could easily be implemented by getting the 3rd decimal and  
using it in

a switch() statement.

An unbiased system could look like:

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

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

Cheers,

Mattias


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



Here you go, Rick.  Just send the check in the mail ;)

function round_to_half_cent($amount)
{
if (!is_numeric($amount)) throw new Exception('The amount received  
by the

round_to_half_cent function was not numeric');
$parts = explode('.', str_replace(',', '', (string)$amount));
if (count($parts) = 3) throw new Exception('The amount received by  
the

round_to_half_cent function had too many decimals.');
if (count($parts) == 1)
{
return $amount;
}
$digit = substr($parts[1], 2, 1);
if ($digit == 0 || $digit == 1 || $digit == 2)
{
$digit = 0;
}
elseif ($digit == 3 || $digit == 4 || $digit == 5 || $digit == 6)
{
$digit = .005;
}
elseif ($digit == 7 || $digit == 8 || $digit == 9)
{
$digit = .01;
}
else
{
throw new Exception('OK, perhaps we are talking about different  
types of

numbers :(  Check the input to the round_to_half_cent function.');
}
return (double)($parts[0].'.'.substr($parts[1], 0, 2)) + $digit;
}

echo 5.002 = .round_to_half_cent(5.002);
echo br /70,000.126 = .round_to_half_cent(7.126);
echo br /55.897 = .round_to_half_cent(55.897);
// should cause exception
echo br /One hundred = .round_to_half_cent(One hundred);

--
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com



 --Rick



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



Re: [PHP] Formatting Decimals Further Help

2010-01-22 Thread Rick Dwyer


On Jan 22, 2010, at 4:24 PM, tedd wrote:


Hello List.

In an earlier post, I received help with a custom function to round  
decimals off (the custom function provided by Adam Richardson is  
below).


However in my MySQL db, when I have values with only 1 decimal  
point, I need the value PHP returns to display as 2.  For example,  
3.8 needs to display as 3.80.


My line of code that calls the custom function looks like this:

$my_price = round_to_half_cent(number_format($my_price, 3, '.',  
','));


When the value of $my_price is 3.81, it returns 3.81.  However,  
when the value of $my_price is 3.8 that is what it returns.


How can I force the formatting of my_price to always contain either  
2 or 3 decimal points (3 if the original number contains 3 or more  
decimal points to begin with)



Thanks,

--Rick



Rick:

Okay so 3.8 is stored in the database and not as 3.80 -- but that's  
not a problem. What you have is a display problem so use one of the  
many PHP functions to display numbers and don't worry about how it's  
stored.



Hi Ted.

This is exactly what I am trying to do, some of the values in the DB  
are going to have 3 decimals, some 2 and some 1.


On my page I pull the value from the db with:

$my_price = $row['my_price'];

This returns 3.80... even though my db has it as 3.8.  No problem.   
But once I run the variable $my_price through the following line of  
code, it is truncating the 0:


$my_price = round_to_half_cent(number_format($my_price, 3, '.', ','));

Again, the above call to the custom function works fine for 2 and 3  
decimal points just not 1 decimal point.  Because I call this  
function over many pages, I would prefer if possible to fix it at the  
custom function level rather than recode each page.  But I will do  
whatever is necessary.  I afraid with my current understanding of PHP  
I am not able to successfully modify the custom function to tack on a  
0 when the decimal place is empty.  Will keep trying and post if I am  
successful


Thanks,

--Rick




I'm afraid with my current understanding of PHP, I am not able to come  
up with the logic to


 --Rick



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



Re: [PHP] Formatting Decimals Further Help

2010-01-22 Thread Rick Dwyer


On Jan 22, 2010, at 7:30 PM, Nathan Rixham wrote:


Thanks Nathan I'll give it a shot.

 --Rick






your doing the number format before the rounding.. here's a version of
the function that should fit the bill:

function round_to_half_cent( $value )
{
$value *= 100;
if( $value == (int)$value || $value  ((int)$value)+0.3 ) {
return number_format( (int)$value/100 , 2);
} else if($value  ((int)$value)+0.6) {
return number_format( (int)++$value/100 , 2);
}
return number_format( 0.005+(int)$value/100 , 3);
}


echo round_to_half_cent( 12.1 );   // 12.10
echo round_to_half_cent( 12.103 ); // 12.105
echo round_to_half_cent( 12.107 ); // 12.11
echo round_to_half_cent( 123456.789 ); // 123,456.79









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



Re: [PHP] Formatting Decimals Further Help

2010-01-22 Thread Rick Dwyer

Thank you Nathan,
This worked quite well.
 --Rick

On Jan 22, 2010, at 8:10 PM, Nathan Rixham wrote:


Rick Dwyer wrote:

On Jan 22, 2010, at 7:30 PM, Nathan Rixham wrote:
Thanks Nathan I'll give it a shot.



np - here's a more condensed version:

function round_to_half_cent( $value )
{
$value = ($value*100) + 0.3;
$out = number_format( floor($value)/100 , 2 );
return $out . ($value  .5+(int)$value ? '5' : '');
}



echo round_to_half_cent( 12.1 );   // 12.10
echo round_to_half_cent( 12.103 ); // 12.105
echo round_to_half_cent( 12.107 ); // 12.11
echo round_to_half_cent( 123456.789 ); // 123,456.79



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








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



Re: [PHP] Formatting Decimals

2010-01-11 Thread Rick Dwyer

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

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


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


Thanks,
--Rick




On Jan 11, 2010, at 10:55 AM, Ryan Sun wrote:


$newprice =  sprintf($%.2f, 15.109);

On Sun, Jan 10, 2010 at 8:36 PM, Rick Dwyer rpdw...@earthlink.net  
wrote:

Hello List.

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


My code looks like this:

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

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


I tried:

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

Any help is appreciated.

Thanks,

 --Rick



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





 --Rick



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



Re: [PHP] Formatting Decimals

2010-01-11 Thread Rick Dwyer


On Jan 11, 2010, at 4:56 PM, tedd wrote:


At 2:55 PM -0500 1/11/10, Rick Dwyer wrote:
I have been asked to further modify the value to the nearest half  
cent.


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


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


Thanks,
--Rick



--Rick:

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


I understand what you are saying and I agree.  But the decision to  
round to half cents as outlined above is a client requirement, not  
mine (I did try to talk them out of it but no luck).


I come from an LDML environment, not a PHP one so I don't know the  
actual code to make this happen.  But the logic would be something like:


If 3 decimal than look at decimal in position 3.

If value = 1 or 2 set it to 0
If value = 3,4,5,6 round it to 5
If value = 7,8,9 round it to a full cent


Anybody have specific code examples to make this happen?

Thanks,

--Rick








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


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

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


Here are some examples:

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

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

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


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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




 --Rick



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



[PHP] Formatting Decimals

2010-01-10 Thread Rick Dwyer

Hello List.

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


My code looks like this:

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

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


I tried:

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

Any help is appreciated.

Thanks,

 --Rick



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



Re: [PHP] Re: First time PHP user question

2010-01-07 Thread Rick Dwyer

Thanks Ashley  Nathan.

As it turns out, there is more than one tmp folder... and I was  
looking in the wrong one.  When I SSH'd in the correct one, I created  
the missing file and it began to work properly.

Thanks for chiming in.

--Rick


On Jan 7, 2010, at 7:58 AM, Ashley Sheridan wrote:


On Thu, 2010-01-07 at 09:19 +, Nathan Rixham wrote:


Rick Dwyer wrote:
 Hello List.
 I have been playing around with PHP, running a few tutorials and  
I came

 across an error message I could not resolve.

 The tutorial is Generating One Time URL's by Oreilly:
 http://www.oreillynet.com/pub/a/php/2002/12/05/one_time_URLs.html

 Basically the PHP code is supposed to read from a text file and  
write to
 a text file and serve a text file all located in the tmp  
directory of

 the server.

 However, I receive the error that the referenced files in the PHP  
code

 could not be found:
 Warning: readfile(/tmp/secret_file.txt) [function.readfile]:  
failed to

 open stream: No such file or directory
 in/home/mysite/myfolder/get_file.php on line 67

 Line 66 and 67 look like this:

 $secretfile = /tmp/secret_file.txt;
 readfile($secretfile);


 However, in the tmp folder, I have created a simple text file  
called
 secret_file.txt so I know it exists and it has the permissions  
set to

 644, so it should be readable.

 Can someone point out to me what I am doing wrong?  Thanks,


try permissions of 777 and see if the error disappears; odds are v  
high

that the httpd user php is running under doesn't have group or owner
permissions for /tmp  that secret file.

regards




That shouldn't fix it. 644 permissions allow the owner, group users  
and anybody else to read file. Have you tried is_file(/tmp/ 
secret_file.txt); to see if it actually exists? Also, don't forget  
that Linux is case sensitive when it comes to filenames, so  
secret_file.txt is completely different from Secret_File.txt, and in- 
fact you can validly have both in the same directory.


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





 --Rick



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



Re: [PHP] Which query is more correct?

2009-11-20 Thread Rick Pasotto
On Fri, Nov 20, 2009 at 04:41:58PM -0600, LAMP wrote:
 Hi,
 I need to pull all records from the table Registrants they are NOT
 in the table ToBeRecleared
 
 Registrants.Reg_ID is PK
 ToBeRecleared.tbrc_Reg_ID is PK
 
 Which query is more correct?
 
 SELECT r.*
 FROM registrants r
 where r.reg_status=1 AND r.reg_id NOT IN (SELECT tbrc_reg_id FROM
 toberecleared)
 
 
 SELECT r.*
 FROM registrants r
 where r.reg_status=1 AND (SELECT count(*) FROM toberecleared where
 tbrc_reg_id=r.reg_id) = 0
 
 I checked explain of bot queries - but can't read them.  :-)

SELECT t1.*
FROM registrants t1
LEFT JOIN ToBeRecleared t2 on t1.reg_id = t2.tbrc_reg_id
where t2.tbrc_reg_id is NULL

-- 
Every major horror of history was committed in the name of an
 altruistic motive. -- Ayn Rand, The Fountainhead, 1943
Rick Pasottor...@niof.nethttp://www.niof.net

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



[PHP] Script sometimes not recognized as php

2009-08-30 Thread Rick Pasotto
I have several LAMP sites on my machine. Occasionally when accessing a
page the browser says the document is of unknown type and wants to know
what to do with it. I click on 'Cancel' and try the page again and this
time it works as it should.

Why would apache *sometimes* fail to interpret a php script as php?

-- 
The difficulties which I meet with in order to realize my existence are
precisely what awaken and mobilize my activities, my capacities.
Rick Pasottor...@niof.nethttp://www.niof.net

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



Re: [PHP] Include Paths

2009-08-12 Thread Rick Duval
SORRY BUT
I CAN'T GET OFF THIS LIST, I CAN'T GET OFF THIS LIST, I CAN'T GET OFF THIS LIST
I'VE TRIED. NO RESPONSE. IS THERE AN ADMIN OUT THERE? PLEASE GET ME
OFF THIS LIST!


This message has been scanned for
viruses and dangerous content by
Accurate Anti-Spam Technologies.
www.AccurateAntiSpam.com



On Wed, Aug 12, 2009 at 11:08 AM, Adam Shannona...@ashannon.us wrote:
 On Wed, Aug 12, 2009 at 10:02 AM, Julian Muscat Doublesin 
 opensourc...@gmail.com wrote:

 I had a problem with the include and require paths when using AJAX. This I
 have solved by using the document root. However since doing so I am
 experiencing performance issues. Loading 20 records has suddenly turned
 into
 something of a matter of a minute rather then seconds.

 Has anyone ever experienced such an issue?

 Can anyone please advise?

 Thanks


 I wonder if loading the script/page with an absolute path would fix the
 problem.



 --
 - Adam Shannon ( http://ashannon.us )

 -
 This message has been scanned for
 viruses and dangerous content by
 Accurate Anti-Spam Technologies.
 www.AccurateAntiSpam.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   >