php-general Digest 14 Nov 2009 21:30:26 -0000 Issue 6442

Topics (messages 299815 through 299822):

Re: is Aptana taking a crap on the face of PHP?
        299815 by: Daevid Vincent

Re: creating combobox in excel sheet?
        299816 by: Kim Madsen

Re: RIGHT Function?
        299817 by: sono-io.fannullone.us
        299818 by: Jim Lucas
        299819 by: sono-io.fannullone.us
        299820 by: sono-io.fannullone.us
        299821 by: Jim Lucas

exec() problem
        299822 by: A. Mannini

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
> -----Original Message-----
> From: tedd [mailto:tedd.sperl...@gmail.com] 
> Sent: Friday, November 13, 2009 6:06 AM
>
> You also have apps like GoLive and Dreamweaver that make excellent 
> IDE's -- you don't have to use the WYSIWYG junk.
> 
> I'm learning to use Eclipse and it's great, but it doesn't handle the 
> hundreds of smaller projects together like GoLive does -- or I 
> haven't learn how to yet.

Just in case you're not clear or haven't used Aptana before. 

* It *is* an Eclipse offering (like Zend) 
* It is NOT a WYSIWYG.
* It has outstanding color-coding, way more than any other IDE I've ever
seen. 
* It Handles jQuery and other JS libraries with completion.
* It does ruby and python as well -- very convenient for someone like me who
works in all three languages.
* It has a very nice code formatter (like Zend has)
* It is FREE (unlike Zend's retarded $500 price tag).


--- End Message ---
--- Begin Message ---
Jim Lucas wrote on 2009-11-13 17:06:
Kim Madsen wrote:
Hey

I'm working on creating excel sheets from these classes:

http://articles.sitepoint.com/article/pear-spreadsheet_excel_writer/3

http://pear.php.net/package/Spreadsheet_Excel_Writer/download/

Does anyone know how to create a combo box from PHP with these (or other
classes)? By combobox I mean the <select> / dropdown box in HTML.

Where will your combobox reside?

In the excel sheet. Let me clarify my last posting:

By combobox I mean _like_ the <select> / dropdown box _is made_ in HTML.

What will your combobox contain/display?

some data, could be "yes", "no", "maybe", these 3 data should be in the dropdown box when the user click the arrow. I simply wanna generate the list I can create in OpenOffice calc by selecting data->validity->criteria and select list in "allow" then adding yes[enter]no[enter]maybe[enter]

What are you going to generating your combobox with?

PHP was the thought, with data from a database

Are you wanting to build it with one of the two listed software packages?

Yes, if possible. Otherwise another class/function is also fine.

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message --- I think I've solved a problem that I had posted back in September. Here's a recap:

======================
I need to grab a dollar amount from a text field in a MySQL db that can contain more information than just the price. Here are 4 examples of what could be in that field:

48,(min)
2.66

24,(min)
10.50

4,(min)
104.82

98.56

If there is more info in that field than just the price (as in the first 3 examples), the price is always on the 2nd line.
======================

The following code works with the tests I've given it so far, but I just want to double check before I go live with it:

...
if ($position = strpos($item['unitprice'], ')') )
$price = "$" . number_format(substr($item['unitprice'], $position + 1),2);
else
        $price = "$" . number_format($item['unitprice'],2);
...

Legend:
$item['unitprice'] is coming from a MySQL statement

I'm grabbing the position of the right parentheses and adding 1 to it. Then the substr grabs everything from that point to the end of the string, correct? If there isn't a ")" in the field, then the else statement should be performed.

Can anyone see any errors in my code? Would there be a better way to write this?

Thanks again,
Frank

--- End Message ---
--- Begin Message ---
sono...@fannullone.us wrote:
>     I think I've solved a problem that I had posted back in September. 
> Here's a recap:
> 
> ======================
>     I need to grab a dollar amount from a text field in a MySQL db that
> can contain more information than just the price.  Here are 4 examples
> of what could be in that field:
> 
> 48,(min)
> 2.66
> 
> 24,(min)
> 10.50
> 
> 4,(min)
> 104.82
> 
> 98.56
> 
>     If there is more info in that field than just the price (as in the
> first 3 examples), the price is always on the 2nd line.
> ======================
> 
>     The following code works with the tests I've given it so far, but I
> just want to double check before I go live with it:
> 
> ...
> if ($position = strpos($item['unitprice'], ')') )
>     $price = "$" . number_format(substr($item['unitprice'], $position +
> 1),2);
> else
>     $price = "$" . number_format($item['unitprice'],2);
> ...
> 

Well, when you put it that way, I would try this.

...

$parts = explode(PHP_EOL, $item['unitprice']);

$price = '$'.(( count($parts) > 1 ) ? $parts[0] : $parts[(count($parts)-1)]);

...






> Legend:
> $item['unitprice'] is coming from a MySQL statement
> 
>     I'm grabbing the position of the right parentheses and adding 1 to
> it.  Then the substr grabs everything from that point to the end of the
> string, correct?  If there isn't a ")" in the field, then the else
> statement should be performed.
> 
>     Can anyone see any errors in my code?  Would there be a better way
> to write this?
> 
> Thanks again,
> Frank
> 


--- End Message ---
--- Begin Message ---
Hi Jim,

$parts = explode(PHP_EOL, $item['unitprice']);

$price = '$'.(( count($parts) > 1 ) ? $parts[0] : $parts[(count($parts)-1)]);

Thanks for the code! After reading up on PHP_EOL and explode, I now understand what you've done. However, can you tell me why you like this better? Is it because it is cleaner without the if/else statements, or is there more to it than that?

Regards,
Frank

--- End Message ---
--- Begin Message ---
Jim,

$parts = explode(PHP_EOL, $item['unitprice']);

$price = '$'.(( count($parts) > 1 ) ? $parts[0] : $parts[(count($parts)-1)]);

For some reason, I couldn't get explode to work with PHP_EOL. $parts[0] would return the entire field, so apparently it wasn't "exploding". So I tried exploding on the ')' instead, which worked, but the return character that's after the ')' was included in the output, i.e.:
$
6.56

so I added 'trim' which took care of that. I also had to use 'number_format' again, since there are exact dollar amounts like 413. Here's what ended up working for me:

$parts = explode(')', $item['unitprice']);
$price = '$'.number_format(trim((( count($parts) > 1 ) ? $parts[(count($parts)-1)] : $parts[0])),2);


Any idea why PHP_EOL didn't work? If I could get it to work, I could remove the trim function and 2 of those parentheses, which would look a lot nicer.

Thanks again,
Frank

--- End Message ---
--- Begin Message ---
sono...@fannullone.us wrote:
Jim,

$parts = explode(PHP_EOL, $item['unitprice']);

$price = '$'.(( count($parts) > 1 ) ? $parts[0] : $parts[(count($parts)-1)]);

For some reason, I couldn't get explode to work with PHP_EOL. $parts[0] would return the entire field, so apparently it wasn't "exploding". So I tried exploding on the ')' instead, which worked, but the return character that's after the ')' was included in the output, i.e.:
$
6.56

so I added 'trim' which took care of that. I also had to use 'number_format' again, since there are exact dollar amounts like 413. Here's what ended up working for me:

$parts = explode(')', $item['unitprice']);
$price = '$'.number_format(trim((( count($parts) > 1 ) ? $parts[(count($parts)-1)] : $parts[0])),2);


Basically, you are using an if-then-else statement.

Read here: 
http://us2.php.net/manual/en/control-structures.alternative-syntax.php

As for the PHP_EOL:

Read here: http://us2.php.net/manual/en/reserved.constants.php
and search for PHP_EOL

You basic problem with the PHP_EOL is that when echo'ed out, it represents a \n 
character.

The value you are working with might be \n\r or just \r

Others: correct me if I'm wrong, but...

Linux, BSD, etc...  use \n as line endings
Windows (All versions) use \r\n
Mac (Old school) used \r
Mac (Current) BSD Style  \n

But, with all that said. Here is the code a little further broken out.


<?php

$parts = preg_split('|[\n\r]+|', $item['unitprice']);

if ( count($parts) > 1 ) {
    $dirty_price = $parts[(count($parts)-1)];
} else {
    $dirty_price = $parts[0];
}

$clean_price = number_format($dirty_price, 2);

?>


Any idea why PHP_EOL didn't work? If I could get it to work, I could remove the trim function and 2 of those parentheses, which would look a lot nicer.

Thanks again,
Frank



--
Jim Lucas

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

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
 Hi all,

i've a problem using exec() on a Linux server with PHP 5.2.9 on Apache 2.2.13. Safe mode is OFF and Apache isn't chrooted.

I would run /usr/lib/mailman/bin/find_member -l <list> <email> so i used exec("sudo run /usr/lib/mailman/bin/find_member -l <list> <email>",$output) and set /etc/sudoers with apache ALL=NOPASSWD: /usr/lib/mailman/bin/find_member but it doesn't work.

I tried simple commands "/bin/ls" works, "sudo -V" work but "sudo /bin/ls" doesn't work.

I get return code 1 and no messages in logs..

What is worng?

Thanks

Alessandro

--- End Message ---

Reply via email to