[PHP] Re: Two very useful PHP functions

2009-04-30 Thread Colin Guthrie

'Twas brillig, and Raymond Irving at 30/04/09 03:32 did gyre and gimble:

Hello,

Every so often I have to be using the isset() function to check if a variable 
exists. It would be useful to have something like an ifset() function

Instead of doing this

$v = isset($input) ? $input : $default;

we can do this

$v = ifset($input,$default); 
// returns $input if it exists otherwise it will return $default


We could also do the same for the empty() function. So instead of doing this

$v = empty($input) ? $default : $input;

we can do this

$v = ifempty($input,$default);
// returns $input if it is not empty otherwise it will return $default

What do you think? Can they make it into 5.3?


To be honest, I don't see the compelling need for this.

I don't disagree that the functionality is nice, however I quite like 
the verbose versions as they are clearer to understand without knowing 
an API function.


Also, most of the cases that you would use these functions are with 
input from GET args and the like. Most frameworks provides wrappers for 
this with handy ways to get the defaults etc.


So overall, I can't see this becoming a core PHP feature.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



Re: [PHP] Boolean Parameter to 3 Options?

2009-04-30 Thread Richard Quadling
2009/4/29 Matt Neimeyer :
> On Wed, Apr 29, 2009 at 1:30 PM, Shawn McKenzie  wrote:
>> Philip Thompson wrote:
>>> On Apr 29, 2009, at 11:42 AM, Matt Neimeyer wrote:
>>>
 I have a function that currently takes a boolean value as a parameter.
 But now I want to expand it to 3 options...  So if I have...

 function doFooBar($doFoo = false)
   {
   if($doFoo)
      { echo "Did Foo"; }
   else
      { echo "Did Bar"; }
   }

 Is it as "simple" as changing it like follows to avoid having to
 change existing code that won't use the new values.

 function doFooBar($doFoo = 0)
   {
   if($doFoo == 2)
      { echo "Did Baz"; }
   else if($doFoo == 1)
      { echo "Did Foo"; }
   else
      { echo "Did Bar"; }
   }

 Something about that disturbs me. Perhaps because any time I think "Oh
 it will be as simple as..." it usually isn't.

 Thanks in advance!

 Matt
>>>
>>> Unless you're doing a strict comparison (===), it probably won't make a
>>> lot of difference. However, if you sent "true" to the function, I
>>> believe it will reach the last else condition. You may revisit all the
>>> locations you call it and update them appropriately.
>>>
>>> Those are my initial thoughts
>>>
>>> ~Philip
>>>
>>
>> No, true will match the first condition.  If you're using true and false
>> now and just want to add a second option then continue using true/false.
>>  Don't mix and match.  1 == true and 2 == true.
>>
>> function doFooBar($doFoo = false)
>> {
>>   if($doFoo === 2) {
>>        //something
>>   }
>>   elseif($doFoo === true) {
>>        //something true
>>   }
>>   elseif($doFoo === false) {
>>        //something false
>>   }
>> }
>>
>
> Ah. I somehow missed the direction of the typecasting. Not that the
> documentation isn't completely explicit on the matter but for some
> reason I was thinking that the bool got cast to 1 or 0... not that the
> string/number got cast to a bool (following the standards there).
>
> Good to know.
>
> Thanks
>
> Matt
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Another way ...



outputs ...

Option 1 chosen
Option 2 chosen
Option 3 chosen
Option 1 chosen
Option 3 chosen


-- 
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

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



[PHP] Getting Sub Elements with XPath

2009-04-30 Thread AngeloZanetti

Hi all, 

I have the following XML returned to us.


















We need to get the values of the FromDay, ToDay and ChargeAmount from the
following sub elements: 




I hve the following code: But I am not able to get the second element's
details: (Charge: false, FromDay: 1)

$Elements = $xpath->query(
'ResponseDetails/SearchChargeConditionsResponse/ChargeConditions/ChargeCondition/',
$responseElement );


foreach( $Elements as $Element ) 
{

$itemStatus = 
$xpath->query('Condition/Charge' , $Element);
$FromDay2 = 
$xpath->query('Condition/FromDay' , $Element);

$condition = 
trim($itemStatus->item(0)->textContent);
echo "CONDITION: #" . 
$condition."#";

$FromDay = 
trim($FromDay2->item(0)->textContent);
echo " FromDay: " . $FromDay;

if ($condition =="true")
{
$ChargeAmount2 = 
$xpath->query('Condition/@ChargeAmount' , $Element);
   
$ChargeAmount = 
trim($ChargeAmount2->item(0)->textContent);
echo "  CHARGE AMT: " . 
$ChargeAmount;

$ToDay = 
$xpath->query('Condition/@ToDay' , $Element);
$ToDay = 
trim($ToDay->item(0)->textContent);
echo " ToDay: " . $ToDay;

}
else if($condition =="false")
{
$FromDay2 = 
$xpath->query('Condition/@FromDay' , $Element);
$FromDay = 
trim($FromDay2->item(0)->textContent);
echo " FromDay: " . $FromDay;
}
}   

It apprears that I need to add a further loop through the "ChargeCondition"
elements, IE

change 

$Elements = $xpath->query(
'ResponseDetails/SearchChargeConditionsResponse/ChargeConditions/ChargeCondition/',
$responseElement );


to

$Elements = $xpath->query(
'ResponseDetails/SearchChargeConditionsResponse/ChargeConditions/',
$responseElement );

Then I can test the type if its "cancellation" and loop through the
subelements (Condition)

Would this appear to be correct?

Anything else that would appear to be incorrect from the above code for the
accompanying structure?

thanks
angelo

-- 
View this message in context: 
http://www.nabble.com/Getting-Sub-Elements-with-XPath-tp23312506p23312506.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] php forms - select menu selected behavior

2009-04-30 Thread Marcus Gnaß
Troy Oltmanns wrote:
> I have the code below being used to rifle through a list of available
> categories and create select options for them. The code is being used to
> query the database and compare the product category to the current
> iteration, if there's a match, then add selected code so the category is
> prechosen. More code (not included) does the saving and all that, I've check
> phpmyadmin. But when the page submits, the old category appears in the drop
> down as selected. If I leave the page and come back it's fine, it's just
> right after it is saved. The form script is being used on itself, in that
> there is only one file for the form, the submission, etc. All of the other
> input elements will load the data after being saved, is it something
> specific to dropdowns, or it is the way the code is being instatiated?
> 
> All help is much appreciated. Please let me know if anymore info is needed.
> 

//MAKE CATEGORIES DROPDOWN

$catlist1 = "";

// read product
$catmatch = "SELECT prod_cat0 FROM product WHERE dbi='$dbi';";
$catresult = mysql_query($catmatch);
$catquery = mysql_fetch_array($catresult);

// read categories
$sql = "SELECT category FROM categories ORDER BY category;";
$result = mysql_query($sql);
while ($col2 = mysql_fetch_array($result)) {

$id = $col2["category"];

if ($id == $catquery['prod_cat0']){

$catlist1 .= "$id";

}   else {

$catlist1 .= "$id";

}

}

> 
> to instantiate 
> 

The only data you need from table product is the column prod_cat0, from
table categories it's category, so you should read only the needed data
instead of using * for better performance.

Take the SQL and verify if it returns what you want it to return then.

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



[PHP] Renaming archive entries doesnt work

2009-04-30 Thread Darren Karstens
Hi,
I am trying to add a prefix to all of the entries in a zip file using
the ZipArchive::renameIndex function which is corrupting the files
when I try to extract them. I was wondering if anyone else has used
this method successfully? Here is the code im using:

$client='TEST';
$zip = new ZipArchive();
if ($zip->open($targetpath,ZIPARCHIVE::OVERWRITE)===true)
{
// prefix all of the files with the clients name
for($i = 0; $i < $zip->numFiles; $i++)
{
$zip->renameIndex($i,$client.$zip->getNameIndex($i));
}
if (!$zip->close()) echo 'Failed to rename zip';
}else echo'Failed to open zip';

This renames the files inside the zip but when I try and extract them
the zip is corrupt.

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



[PHP] Warning: Division by zero

2009-04-30 Thread Gary
I have a script that is a result of data entered in a form

On the script (when I test without data entry), I am getting a warning that 
Warning: Division by zero in .inc.php on line 15.

The warning is correct, however the viewer cannot access the second script 
without entering the data that would cancel the warning.

Is this something I should worry about? or would it be better to right in an 
isset?

I'm sorry if this does not seem clear. 



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



RE: [PHP] Warning: Division by zero

2009-04-30 Thread kyle.smith
It's always better to validate your inputs in any was possible, this
helps prevent exploits. 

-Original Message-
From: Gary [mailto:gwp...@ptd.net] 
Sent: Thursday, April 30, 2009 8:51 AM
To: php-general@lists.php.net
Subject: [PHP] Warning: Division by zero

I have a script that is a result of data entered in a form

On the script (when I test without data entry), I am getting a warning
that
Warning: Division by zero in .inc.php on line 15.

The warning is correct, however the viewer cannot access the second
script without entering the data that would cancel the warning.

Is this something I should worry about? or would it be better to right
in an isset?

I'm sorry if this does not seem clear. 



--
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] Warning: Division by zero

2009-04-30 Thread Christoph Boget
> I have a script that is a result of data entered in a form
> On the script (when I test without data entry), I am getting a warning that
> Warning: Division by zero in .inc.php on line 15.
> The warning is correct, however the viewer cannot access the second script
> without entering the data that would cancel the warning.
> Is this something I should worry about? or would it be better to right in an
> isset?

Well, just as a general rule, you'll want to validate all possible
user input.  That includes checking whether or not particular input
has been defined, whether or not it is valid for it's intended use and
whether or not it's malicious.

Applying that guideline to your situation, I would check to see if:

* the input is set
* the input is numeric

If either or those are not true, I would default the value to 1 since
division is being used. e.g.,

$iVar = 1;
if(( isset( $_REQUEST['MY_NUMBER'] ) && ( is_numeric(
$_REQUEST["MY_NUMBER']))) {
  $iVar = $_REQUEST['MY_NUMBER'];
}

$iCalculatedValue = $x / $iVar;

thnx,
Christoph

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



[PHP] Re: Static and/or Dynamic site scraping using PHP

2009-04-30 Thread 9el
On Thu, Apr 30, 2009 at 3:33 AM, 9el  wrote:
> I just got a project to do on PHP of scraping the body items from
> static sites or just html sites.
> Could you experts please suggest me some quick resources?
>
> I have to make an WP plugin with the data as well.

Any expert there yet? Was looking for urgent advices on accomplishing the task.

Thanks

Lenin

www.twitter.com/nine_L

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



Re: [PHP] Getting Sub Elements with XPath

2009-04-30 Thread Andrew Ballard
On Thu, Apr 30, 2009 at 5:02 AM, AngeloZanetti  wrote:
>
> Hi all,
>
> I have the following XML returned to us.
>
> 
>
>
>
>
> ToDay="0" Currency="ZAR"
> ChargeAmount="320.00"/>
>
>
> MaximumPossibleChargesShown="true">
>
>
>
>
>
>
> 
>
> We need to get the values of the FromDay, ToDay and ChargeAmount from the
> following sub elements:
>
>  ChargeAmount="320.00"/>
> 
>
> I hve the following code: But I am not able to get the second element's
> details: (Charge: false, FromDay: 1)
>
> $Elements = $xpath->query(
> 'ResponseDetails/SearchChargeConditionsResponse/ChargeConditions/ChargeCondition/',
> $responseElement );
>
>
>foreach( $Elements as $Element )
>{
>
>$itemStatus = 
> $xpath->query('Condition/Charge' , $Element);
>$FromDay2 = 
> $xpath->query('Condition/FromDay' , $Element);
>
>$condition = 
> trim($itemStatus->item(0)->textContent);
>echo "CONDITION: #" . 
> $condition."#";
>
>$FromDay = 
> trim($FromDay2->item(0)->textContent);
>echo " FromDay: " . $FromDay;
>
>if ($condition =="true")
>{
>$ChargeAmount2 = 
> $xpath->query('Condition/@ChargeAmount' , $Element);
>$ChargeAmount = 
> trim($ChargeAmount2->item(0)->textContent);
>echo "  CHARGE AMT: " . 
> $ChargeAmount;
>
>$ToDay = 
> $xpath->query('Condition/@ToDay' , $Element);
>$ToDay = 
> trim($ToDay->item(0)->textContent);
>echo " ToDay: " . $ToDay;
>
>}
>else if($condition =="false")
>{
>$FromDay2 = 
> $xpath->query('Condition/@FromDay' , $Element);
>$FromDay = 
> trim($FromDay2->item(0)->textContent);
>echo " FromDay: " . $FromDay;
>}
>}
>
> It apprears that I need to add a further loop through the "ChargeCondition"
> elements, IE
>
> change
>
> $Elements = $xpath->query(
> 'ResponseDetails/SearchChargeConditionsResponse/ChargeConditions/ChargeCondition/',
> $responseElement );
>
>
> to
>
> $Elements = $xpath->query(
> 'ResponseDetails/SearchChargeConditionsResponse/ChargeConditions/',
> $responseElement );
>
> Then I can test the type if its "cancellation" and loop through the
> subelements (Condition)
>
> Would this appear to be correct?
>
> Anything else that would appear to be incorrect from the above code for the
> accompanying structure?
>
> thanks
> angelo
>

You might be able to cut down your code further with something like this:

query(
"ResponseDetails/SearchChargeConditionsResponse/ChargeConditions/chargeconditi...@type='cancellation']/Condition",
$responseElement );


foreach( $Elements as $Element )
{

$condition = $Element->getAttribute('Charge');
$FromDay = $Element->getAttribute('FromDay');

echo "CONDITION: #" . $condition."#";

echo " FromDay: " . $FromDay;

if ($condition =="true")
{
   $ChargeAmount = $Element->getAttribute('ChargeAmount');
   echo "  CHARGE AMT: " . $ChargeAmount;

   $ToDay = $Element->getAttribute('ToDay');
   echo " ToDay: " . $ToDay;

}
else if($condition =="false")
{
   echo " FromDay: " . $FromDay;
}
}

?>

I'm not sure if you really want it to print FromDay twice in the case
that Charge == 'false', but you should be able to sort that out.

Andrew

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



Re: [PHP] Warning: Division by zero

2009-04-30 Thread Gary
Thanks for your response.

The error I am getting is when I am defining a variable.

(line 15) $percent_difference=($assess_difference)/($assess_value);

Does this make a difference?

Thanks again for all your help.

Gary


"Christoph Boget"  wrote in message 
news:540509760904300600i7af94667w6bad30ed068d1...@mail.gmail.com...
>> I have a script that is a result of data entered in a form
>> On the script (when I test without data entry), I am getting a warning 
>> that
>> Warning: Division by zero in .inc.php on line 15.
>> The warning is correct, however the viewer cannot access the second 
>> script
>> without entering the data that would cancel the warning.
>> Is this something I should worry about? or would it be better to right in 
>> an
>> isset?
>
> Well, just as a general rule, you'll want to validate all possible
> user input.  That includes checking whether or not particular input
> has been defined, whether or not it is valid for it's intended use and
> whether or not it's malicious.
>
> Applying that guideline to your situation, I would check to see if:
>
> * the input is set
> * the input is numeric
>
> If either or those are not true, I would default the value to 1 since
> division is being used. e.g.,
>
> $iVar = 1;
> if(( isset( $_REQUEST['MY_NUMBER'] ) && ( is_numeric(
> $_REQUEST["MY_NUMBER']))) {
>  $iVar = $_REQUEST['MY_NUMBER'];
> }
>
> $iCalculatedValue = $x / $iVar;
>
> thnx,
> Christoph 



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



Re: [PHP] Warning: Division by zero

2009-04-30 Thread Christoph Boget
> The error I am getting is when I am defining a variable.
> (line 15) $percent_difference=($assess_difference)/($assess_value);
> Does this make a difference?

No, it doesn't make a difference.  The simple fact is that
$assess_value is either undefined or has been set to 0 at some point.
For it's use in the above equation, neither case is valid.
Consequently, you really should be doing some validation at some point
prior to that line.

thnx,
Christoph

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



Re: [PHP] utf-8 ?

2009-04-30 Thread Tom Worster
On 4/29/09 6:52 PM, "Reese"  wrote:

> Tom Worster wrote:
>> On 4/28/09 4:05 PM, "Reese"  wrote:
>> 
>>> Granted, this isn't a PHP question but I'm curious, how does UTF-8 solve
>>> this display issue?
>> 
>> if we're talking about web browsers, they are quite good at automatically
>> choosing fonts that can display the unicode characters it finds in a page.
> 
> Right, and I figured out the bit that was confusing me earlier: years
> ago, I read that some encodings such as “ and ” (curly
> quotes) should not be used, that “ and ” should be used
> instead. I misremembered that, when I looked at the utf-8 charset here:
> 
> http://www.columbia.edu/kermit/utf8-t1.html
> 
> I stand apprised and enlightened. I found the encodings for letters G
> with breve, S with cedilla, and lower case I w/out the dot, too.

why use SGML character entity references in a utf-8 file or stream? can't
you just put the character in the file?



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



[PHP] Re: Static and/or Dynamic site scraping using PHP

2009-04-30 Thread Shawn McKenzie
9el wrote:
> On Thu, Apr 30, 2009 at 3:33 AM, 9el  wrote:
>> I just got a project to do on PHP of scraping the body items from
>> static sites or just html sites.
>> Could you experts please suggest me some quick resources?
>>
>> I have to make an WP plugin with the data as well.
> 
> Any expert there yet? Was looking for urgent advices on accomplishing the 
> task.
> 
> Thanks
> 
> Lenin
> 
> www.twitter.com/nine_L

If you're just capturing and using the body, the load with
file_get_contents() and use preg_match() to select the body or
individual tags, etc...  For more control, maybe try this:

$doc = new DOMDocument();
$doc->loadHTMLFile('http://example.com/page.html');

Then use:  http://php.net/manual/book.dom.php

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

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



Re: [PHP] Two very useful PHP functions

2009-04-30 Thread Daniel Brown
On Wed, Apr 29, 2009 at 22:32, Raymond Irving  wrote:
>
> What do you think? Can they make it into 5.3?

Not when doing the ternary operator that you even displayed
yourself takes up less code and time than a core function would.  It's
a good idea, but better handled on the frontend of things.  You may
want to consider contributing that to a framework, which is where it
would be more appropriate.

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1

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



[PHP] $this = new Class();

2009-04-30 Thread Olivier Lalonde
Hi all,

Since I can't do $this = new Class(); within my class (it gives an
error), I was looking for ways to get the same result by other means.

I am actually working on an ORM and trying to implement lazy loading.

$book = $orm->getBook('id'); // returns an Orm object
$book->load();

// $book should now be a Book instead instead of an Orm instance

Of course, I oversimplified the problem.  $book = $orm->getBook('id');
doesn't return a Book instance right ahead because it is a chained
method (i.e. $orm->getBook()->where(...)->prefetch(...)->etc
Therefore, it _has_ to return an Orm instance.

Now, why not simply add ->load() at the end of the chain? Because it
adds an extra step for developers that doesn't bring meaningful
information. Instead of doing $book = $orm->getBook('id');, it would
mean having to do $book = $orm->getBook('id')->load(); (which is
longer to type :p). That's why I wanted to implement "lazy loading".

$book = $dorm->getBook('id');
echo $book->title; // title should be trapped by __set() and it should
dynamically replace $book by an actual Book instance

I tried doing the following, but PHP doesn't allow it:

class A {
  public function transform() {
$this = new B();
  }
}

class B {}

$var = new A();
$var->transform();

This is not currently supported by PHP and I was wondering if there
was anyway of getting around the problem, that doesn't involve
1) passing $var to the A class i.e:$var->var = $var;
2) looping $GLOBALS[]
3) using __call,__get and __set to proxy everything to the actual Book object

PS1: don't lecture me about how I'm doing this all wrong. I've looked
at the problem from every possible angle and this is the only
solution.
PS2: Another alternative would be to subclass the Orm object with
Book, (class Orm extends Book {}), overload all properties/methods so
we can catch when to load the object... but that would be an extreme
pain in the ass.
PS3: Another alternative would be to have a parameter that
enables/disables chaining.
$dorm->getBook('id', true); // chain (you now have to add ->load() at
the end of the chain)
$dorm->getBook('id', false); // dont chain, this returns a Book instance

The point of all this is to keep the most friendly interface !

Cheers,
Olivier

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



Re: [PHP] php forms - select menu selected behavior

2009-04-30 Thread Ashley Sheridan
On Thu, 2009-04-30 at 11:06 +0200, Marcus Gnaß wrote:
> Troy Oltmanns wrote:
> > I have the code below being used to rifle through a list of available
> > categories and create select options for them. The code is being used to
> > query the database and compare the product category to the current
> > iteration, if there's a match, then add selected code so the category is
> > prechosen. More code (not included) does the saving and all that, I've check
> > phpmyadmin. But when the page submits, the old category appears in the drop
> > down as selected. If I leave the page and come back it's fine, it's just
> > right after it is saved. The form script is being used on itself, in that
> > there is only one file for the form, the submission, etc. All of the other
> > input elements will load the data after being saved, is it something
> > specific to dropdowns, or it is the way the code is being instatiated?
> > 
> > All help is much appreciated. Please let me know if anymore info is needed.
> > 
> 
> //MAKE CATEGORIES DROPDOWN
> 
> $catlist1 = "";
> 
> // read product
> $catmatch = "SELECT prod_cat0 FROM product WHERE dbi='$dbi';";
> $catresult = mysql_query($catmatch);
> $catquery = mysql_fetch_array($catresult);
> 
> // read categories
> $sql = "SELECT category FROM categories ORDER BY category;";
> $result = mysql_query($sql);
> while ($col2 = mysql_fetch_array($result)) {
> 
>   $id = $col2["category"];
> 
>   if ($id == $catquery['prod_cat0']){
> 
>   $catlist1 .= " selected=\"selected\">$id";
> 
>   }   else {
> 
>   $catlist1 .= "$id";
> 
>   }
> 
> }
> 
> > 
> > to instantiate 
> > 
> 
> The only data you need from table product is the column prod_cat0, from
> table categories it's category, so you should read only the needed data
> instead of using * for better performance.
> 
> Take the SQL and verify if it returns what you want it to return then.
> 
I tend to do my loops like this:

while ($col2 = mysql_fetch_array($result))
{
$id = $col2["category"];
$selected =($id == $catquery['prod_cat0'])?'selected="selected"':'';

$catlist1 .= "$id";
}

Just looks a little neater. 'Course, you could remove the $id line and
chuck the value straight into the short if statement there.


Ash
www.ashleysheridan.co.uk


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



[PHP] object literals

2009-04-30 Thread Tom Worster
is there a neat literal syntax for creating objects on the fly without
defining a type?

whenever i need to do it i do something like

$x = (object) array('a'=>1, 'b'=>3, ...);

which works but isn't very lovely. it's neater in, for example, javascript.



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



Re: [PHP] utf-8 ?

2009-04-30 Thread Reese

Tom Worster wrote:


why use SGML character entity references in a utf-8 file or stream? can't
you just put the character in the file?


Because, I thought, HTML files were basically just text files with
different file extensions, and that those other characters would not
store or display properly if saved in .txt format. Was I mistaken?

http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt

That is supposed to be a UTF-8 encoded text file, between 1/3 and 1/2
of the characters do not display correctly on my screen. Either way,
this next link suggests that Turkish characters with no equivalent in
the English language should be encoded for Web display:

http://webdesign.about.com/od/localization/l/blhtmlcodes-tr.htm

And because that is off-topic, I'll throw this in:

The consensus seems to be that the proposed "ifset()" and "ifempty()"
functions are more effort than they are worth. What I'd like to know
is, why "empty()" still exists when every time I turn around, the
mentors I turn to locally tell me not to use it, to use "isset()"
instead. Because empty() doesn't work with zero. Anyone care to take
a stab at that?

Reese


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



Re: [PHP] utf-8 ?

2009-04-30 Thread Andrew Hucks
It'd be a hassle to just remove a function from a language, I suppose...

On Thu, Apr 30, 2009 at 6:15 PM, Reese  wrote:
> Tom Worster wrote:
>
>> why use SGML character entity references in a utf-8 file or stream? can't
>> you just put the character in the file?
>
> Because, I thought, HTML files were basically just text files with
> different file extensions, and that those other characters would not
> store or display properly if saved in .txt format. Was I mistaken?
>
> http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt
>
> That is supposed to be a UTF-8 encoded text file, between 1/3 and 1/2
> of the characters do not display correctly on my screen. Either way,
> this next link suggests that Turkish characters with no equivalent in
> the English language should be encoded for Web display:
>
> http://webdesign.about.com/od/localization/l/blhtmlcodes-tr.htm
>
> And because that is off-topic, I'll throw this in:
>
> The consensus seems to be that the proposed "ifset()" and "ifempty()"
> functions are more effort than they are worth. What I'd like to know
> is, why "empty()" still exists when every time I turn around, the
> mentors I turn to locally tell me not to use it, to use "isset()"
> instead. Because empty() doesn't work with zero. Anyone care to take
> a stab at that?
>
> Reese
>
>
> --
> 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] Bhups on the go for a Charity Walk! - Any support appreciated.

2009-04-30 Thread memberservi...@justgiving.com

Hello!

I'm taking part in the ISSO Seva Charity Walk 2009 on 19/07/2009 to raise money 
for International Swaminarayan Satsang Organisation and I'd really appreciate 
your support.

It's easy to sponsor me online by credit or debit card - just go to my 
Justgiving page: 

http://www.justgiving.com/bhupspatel

Justgiving sends your donation straight to International Swaminarayan Satsang 
Organisation and automatically reclaims Gift Aid if you're a UK taxpayer, so 
your donation is worth even more. I hope you'll join me in supporting 
International Swaminarayan Satsang Organisation.

Thank you.

Bhupendra

P.S. I used Justgiving to send this email, so please don't reply to it. Replies 
will go to Justgiving, not to me!



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



Re: [PHP] utf-8 ?

2009-04-30 Thread Tom Worster
On 4/30/09 6:15 PM, "Reese"  wrote:

> Tom Worster wrote:
> 
>> why use SGML character entity references in a utf-8 file or stream? can't
>> you just put the character in the file?
> 
> Because, I thought, HTML files were basically just text files with
> different file extensions, and that those other characters would not
> store or display properly if saved in .txt format. Was I mistaken?

yes. see http://www.w3.org/TR/html401/charset.html

which says that html uses the UCS, a character-by-character equivalent to
the Unicode character set. so if you use a unicode character encoding (such
as utf-8) then you you have a direct encoding for every unicode character in
html.

so a utf-8 html file or stream should normally to have no entities other
than <, >, $amp; and perhaps " as needed.

texts file may be utf-8 encoded too. xml, json and csv files are more
examples of text files that can be utf-8 encoded and use any unicode
character simply and directly. windows and os-x have used utf-8 as their
default text file encoding for many years now.


> http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt
> 
> That is supposed to be a UTF-8 encoded text file, between 1/3 and 1/2
> of the characters do not display correctly on my screen.

this page looks great to me. i don't appear to have the runes or amharic
fonts on my computer so those aren't showing but everything else works.

why this doesn't work for you is not clear. it could be that your browser
has a preference configured to override the charset specified in the http
headers. or perhaps the browser does not observe the specified content type
for txt files.


> Either way,
> this next link suggests that Turkish characters with no equivalent in
> the English language should be encoded for Web display:
> 
> http://webdesign.about.com/od/localization/l/blhtmlcodes-tr.htm

don't believe everything you read on the web. while some browsers may
tolerate it, i don't think pages encoded according to those suggestions
would even be valid html.


> And because that is off-topic, I'll throw this in:
> 
> The consensus seems to be that the proposed "ifset()" and "ifempty()"
> functions are more effort than they are worth. What I'd like to know
> is, why "empty()" still exists when every time I turn around, the
> mentors I turn to locally tell me not to use it, to use "isset()"
> instead. Because empty() doesn't work with zero. Anyone care to take
> a stab at that?

perhaps because it's hard to get rid of language elements without breaking
existing code?



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



Re: [PHP] utf-8 ?

2009-04-30 Thread Chris



The consensus seems to be that the proposed "ifset()" and "ifempty()"
functions are more effort than they are worth. What I'd like to know
is, why "empty()" still exists when every time I turn around, the
mentors I turn to locally tell me not to use it, to use "isset()"
instead. Because empty() doesn't work with zero. Anyone care to take
a stab at that?


They serve different purposes and both work very well.

$form_errors = array();

// process form
foreach (array('name', 'email') as $field) {
  # Hey! someone hacked the form! This field is supposed to be there!
  if (!isset($_POST[$field])) {
$form_errors[] = 'Field ' . $field . ' was missing';
continue;
  }

  # The field is there but has no value.
  if (empty($_POST[$field])) {
$form_errors[] = 'Field ' . $field . ' was empty';
  }
}

if (!empty($form_errors)) {
  echo 'there were errors in processing the form.';
  exit;
}

--
Postgresql & php tutorials
http://www.designmagick.com/


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



[PHP] Eclipse, PDT plugins for hosting, scaling and managing PHP apps.

2009-04-30 Thread Kevin Hakman

re: Eclipse, PDT plugins for hosting, scaling and managing PHP apps.

Aptana has released a new suite of tools for PHP developers that extends the 
popular
Eclipse PDT environment. The plugin for Eclipse, called Aptana Cloud 
Connect, lets
you get all the benefits of scalable, on-demand PHP hosting in the Cloud 
with the ease
of integration right into Eclipse and PDT (You can plug it into Zend Studio 
as well).


A few clicks is all that's needed to get a running PHP, MySQL, Apache 
environment
running in about one minute.  Then the plugin lets you instantly scale your 
web and
database servers in the Cloud up or down anytime.  There's a very useful set 
of visual
database tools for working with your remote database.   For file transfers, 
there's a
"Smart Sync" utility that help you keep local projects coordinated with the 
remote sites.

You can do single file uploads/download and edits as well.

Try it out by adding Aptana Cloud Connect to your Eclipse 3.4 PDT 
installation.


Download and install instructions: 
http://update.aptana.com/install/cloudconnect/


More info at http://www.aptana.com/cloud 



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



Re: [PHP] DateInterval

2009-04-30 Thread MIke Alaimo

Ah.  This makes perfect sense.  Good idea.

Mike

Raymond Irving wrote:


--- On Wed, 4/29/09, MIke Alaimo  wrote:
  

Raymond, have you tried using DateTime::modify?  It
appears to work like strtotime.
also DateTime::format works like date.  At least as
far as I can tell.





From the little documentation that I've seen it appears that it's similar to 
strtotime and date but it would be very good if the PHP devs could make 
strtotime() and date() become wrappers for DateTime::modify and 
DateTime::format. This way we dont hae to modify our code when moving to a 
version of PHP that supports the new DateTime class.

__
Raymond Irving

  



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



Re: [PHP] Two very useful PHP functions

2009-04-30 Thread Raymond Irving

Hi Colin and Daniel,

Thanks for the feedback.

I know that this functionality can be added to a framework or a stand alone 
function but I'm assuming that we would not get the same performance:

Case 1
---
$c = isset($a) ? $a : ''; 
// total time = overhead  of isset() + overhead of ?:

Case 2
---
$c = myWrapper($a,$b)  
// total time = overhead of myWrapper() + overhead of isset() + overhead of ?:

Case 3
---
$c = ifset($a,$b)  
// total time = overhead of ifset()



Best regards

__
Raymond Irving

--- On Thu, 4/30/09, Daniel Brown  wrote:

> From: Daniel Brown 
> Subject: Re: [PHP] Two very useful PHP functions
> To: "Raymond Irving" 
> Cc: php-general@lists.php.net
> Date: Thursday, April 30, 2009, 11:37 AM
> On Wed, Apr 29, 2009 at 22:32,
> Raymond Irving 
> wrote:
> >
> > What do you think? Can they make it into 5.3?
> 
>     Not when doing the ternary operator that you
> even displayed
> yourself takes up less code and time than a core function
> would.  It's
> a good idea, but better handled on the frontend of
> things.  You may
> want to consider contributing that to a framework, which is
> where it
> would be more appropriate.
> 
> -- 
> 
> daniel.br...@parasane.net
> || danbr...@php.net
> http://www.parasane.net/ || http://www.pilotpig.net/
> 50% Off All Shared Hosting Plans at PilotPig: Use Coupon
> DOW1
>

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



[PHP] ImageMagick

2009-04-30 Thread Michael A. Peters

Here's the scenario -

Website has some demonstrative images.

I create these images with the gimp - starting with a jpeg, adding a few 
text layers and straight lines.


I then save as xcf in case I ever need to edit.

Then I export to jpeg, resize for thumb and export to jpeg again.

Admin interface to my web face needs to allow for upload of image.

What would be sweet is if I could just upload the gimp xcf in these 
cases, and have ImageMagick do the export to jpeg and thumbnail creation.


Advantage of doing it this way - it will allow me to keep the original 
xcf on the server along with the generated images.


Issues -

I'd rather not have any code that spawns a shell, so I can only do this 
if the pecl imageMagick module is up to snuff for xcf->jpeg conversion. 
Anyone used it? Looks like I'll have to compile it, before I do that I 
would like to know if it even is up to the task.


Second possible issue - I don't know how well imageMagick can deal with 
an xcf file that uses text layer / fonts. I assume I'll have to install 
the font used on the server (Adobe New Century Schoolbook Type 1 - yes, 
I have license for it), but if so, how would I specify to ImageMagick 
the font path?


Anyone done this sort of thing?

I may just do the export on my home box via gimp and just scp the xcf to 
the server so a copy is stored there as well, but it would be nice to 
just stick the xcf into a file upload field and just have php do the rest.


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



Re: [PHP] ImageMagick

2009-04-30 Thread Ashley Sheridan
On Thu, 2009-04-30 at 23:35 -0700, Michael A. Peters wrote:
> Here's the scenario -
> 
> Website has some demonstrative images.
> 
> I create these images with the gimp - starting with a jpeg, adding a few 
> text layers and straight lines.
> 
> I then save as xcf in case I ever need to edit.
> 
> Then I export to jpeg, resize for thumb and export to jpeg again.
> 
> Admin interface to my web face needs to allow for upload of image.
> 
> What would be sweet is if I could just upload the gimp xcf in these 
> cases, and have ImageMagick do the export to jpeg and thumbnail creation.
> 
> Advantage of doing it this way - it will allow me to keep the original 
> xcf on the server along with the generated images.
> 
> Issues -
> 
> I'd rather not have any code that spawns a shell, so I can only do this 
> if the pecl imageMagick module is up to snuff for xcf->jpeg conversion. 
> Anyone used it? Looks like I'll have to compile it, before I do that I 
> would like to know if it even is up to the task.
> 
> Second possible issue - I don't know how well imageMagick can deal with 
> an xcf file that uses text layer / fonts. I assume I'll have to install 
> the font used on the server (Adobe New Century Schoolbook Type 1 - yes, 
> I have license for it), but if so, how would I specify to ImageMagick 
> the font path?
> 
> Anyone done this sort of thing?
> 
> I may just do the export on my home box via gimp and just scp the xcf to 
> the server so a copy is stored there as well, but it would be nice to 
> just stick the xcf into a file upload field and just have php do the rest.
> 
Do the text layers have to go beneath something on the original xcf, or
have special effects applied to them? If not, you can add t existing
images with GD, by using a source image, adding text layers, etc, and
then exporting it as a new graphic.


Ash
www.ashleysheridan.co.uk


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