php-general Digest 14 Jul 2011 22:27:26 -0000 Issue 7402

Topics (messages 314064 through 314083):

Re: PHP control structure
        314064 by: Richard Quadling

Re: Your language sucks because...
        314065 by: Ashley Sheridan
        314066 by: Richard Quadling
        314067 by: Richard Quadling
        314074 by: George Langley
        314077 by: Micky Hulse

Re: What is a label?
        314068 by: Steve Staples
        314069 by: Stuart Dallas
        314070 by: Steve Staples
        314071 by: Richard Quadling
        314073 by: Daniel Brown

Re: Serveside Printing w/ PHP
        314072 by: Marc Guay

PHP 5.3.7RC3 Released for Testing
        314075 by: Ilia Alshanetsky

Re: IF stream lining
        314076 by: Shawn McKenzie

Variable scope
        314078 by: Karl DeSaulniers
        314080 by: Shawn McKenzie
        314081 by: Tamara Temple
        314082 by: Karl DeSaulniers

problem with session_write_close
        314079 by: Tamara Temple

Re: str_replace around a character??
        314083 by: Shawn McKenzie

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 ---
On 14 July 2011 05:15, Negin Nickparsa <nickpa...@gmail.com> wrote:
> if the problem is only the assigning it's an example:
> in mysql you can have this one:
> create table store_list(id_markets int auto_increment,store_type int,primary
> key(id_markets));
>
> and for page this one:
>
> <html>
>
> <head>
> <title>Store</title>
> </head>
> <form method="post">
> <?php
> $connection=Mysql_connect('localhost','admin','123');
> Mysql_select_db('net',$connection);
> if(array_key_exists('sub',$_POST))
> if(isset($_POST['store_type']) )
> {
> $Type =$_POST['store_type'];
> $ID=$_POST['id'];
>  $sql ="update store_list set store_type=$Type where id_markets=$ID";
> $res = mysql_query($sql,$connection);
> }
> ?>
> <select name='store_type'>
> <option value=0>store type<option>
> <option value=1>corporate<option>
> <option value=2>standard<option>
> </select>
> ID:<input type='text' name='id'>
> <input type='submit' name='sub' value='update the type'>
> </form>
> </html>
>
> also I didn't understand your code that you have 'id_store' and 'id_markets'
> it's confusing for me
>
> if it wasn't your problem please clarify your question maybe I can help.
>

I'd do this in the SQL...


SELECT DISTINCT
        store_type,
        CASE store_type
                WHEN 1 THEN 'Corporate'
                WHEN 2 THEN 'Standard'
                ELSE 'Unknown store_type ' + CAST(store_type AS VARCHAR())
                END AS store_type_desc
FROM
        store_list
WHERE
        id_markets=$_POST[id];

Though for the text, I'd probably have a store_types table so I can
label them there and hold additional data about the store types if
needed.

SELECT DISTINCT
        store_type,
        COALESCE(store_type_desc, 'Unknown store_type ' + CAST(store_type AS
VARCHAR())) AS store_type_desc
FROM
        store_list
        LEFT OUTER JOIN
        store_types ON store_list.store_type = store_types.store_type
WHERE
        id_markets=$_POST[id];


-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--- End Message ---
--- Begin Message ---


>Particularly as it's written by a fathead who thinks that "lose" is
>spelt "loose".
>
>--
>Cheers  --  Tim
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

That's a massive pet hate of mine, along with using here/hear in the wrong way 
and those who have no idea of the difference between "there", "their" & 
"they're". Makes me want to beat them upside the head with a dictionary :)
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

--- End Message ---
--- Begin Message ---
On 14 July 2011 11:36, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
> That's a massive pet hate of mine, along with using here/hear in the wrong 
> way and those who have no idea of the difference between "there", "their" & 
> "they're". Makes me want to beat them upside the head with a dictionary :)
> Thanks,
> Ash

Its all a matter of perspective isnt it? ;-) (here fishy fishy)

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--- End Message ---
--- Begin Message ---
> On 14 July 2011 11:36, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
> Makes me want to beat them upside the head with a dictionary :)

In our house, our Big Red Book _IS_ a massive Oxford Dictionary.

We play a game with the kids. Think of 3 random letters and find a
word starting with it.

My daughter (6 or 7 at the time) came up with T, M and E. I was
abso-bloody-lutely amazed she managed to find a word starting with T,
M and E.

Richard.

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--- End Message ---
--- Begin Message ---
On 2011-07-14, at 4:36 AM, Ashley Sheridan wrote:

> 
> That's a massive pet hate of mine, along with using here/hear in the wrong 
> way and those who have no idea of the difference between "there", "their" & 
> "they're". Makes me want to beat them upside the head with a dictionary :)
----------------
        Mine are it's and its (Remember: it's its!), people who say "people 
that" (It should be "People WHO!") and the complete lack of regard to plural 
versus singular verbs ("There's lots?" "No, there ARE lots of examples of that 
out there!").
        As far as the original list:

http://wiki.theory.org/YourLanguageSucks#PHP_sucks_because:

it's just a tongue-in-cheek way to point out inconsistencies in the various 
languages. However, is kind of out-dated, referring to PHP 4 and CSS 2, so am 
wondering how many of the entries have been rectified? (For instance, CSS 3 
does have multiple background images.) As well, I suspect that some of them may 
actually make sense if analyzed as to why they are that way, instead of how the 
author has grouped them.


George Langley
Multimedia Developer


--- End Message ---
--- Begin Message ---
On Thu, Jul 14, 2011 at 4:02 AM, Richard Quadling <rquadl...@gmail.com> wrote:
> My daughter (6 or 7 at the time) came up with T, M and E. I was
> abso-bloody-lutely amazed she managed to find a word starting with T,
> M and E.

What was the word?

--- End Message ---
--- Begin Message ---
On Wed, 2011-07-13 at 23:27 +0100, Tim Streater wrote:
> On 13 Jul 2011 at 22:39, Micky Hulse <rgmi...@gmail.com> wrote: 
> 
> > They must mean labels as in "general naming convention rules for
> > programming"... Like not naming a variable/function "label" with a number at
> > the front.
> >
> > Here's a page about variables:
> >
> > http://www.php.net/manual/en/language.variables.basics.php
> >
> > Variable names follow the same rules as other labels in PHP. A valid
> > variable name starts with a letter or underscore, followed by any
> > number of letters, numbers, or underscores. As a regular expression,
> > it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
> 
> Except that variables are case-sensitive whereas function names are not. And 
> if there's going to be a formal or "programmatic" definition, then I think 
> I'd prefer BNF to a regexp.
> 
> --
> Cheers  --  Tim
> 

Isn't that statement a little misleading?

> A valid variable name starts with a letter or underscore

If I am not mistaken, $_1 is not a valid variable name.  

Steve.


--- End Message ---
--- Begin Message ---
On Thu, Jul 14, 2011 at 1:37 PM, Steve Staples <sstap...@mnsi.net> wrote:

> On Wed, 2011-07-13 at 23:27 +0100, Tim Streater wrote:
> > A valid variable name starts with a letter or underscore
>
> If I am not mistaken, $_1 is not a valid variable name.


You are mistaken. Try it.

-Stuart

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

--- End Message ---
--- Begin Message ---
On Thu, 2011-07-14 at 13:39 +0100, Stuart Dallas wrote:
> On Thu, Jul 14, 2011 at 1:37 PM, Steve Staples <sstap...@mnsi.net> wrote:
> 
> > On Wed, 2011-07-13 at 23:27 +0100, Tim Streater wrote:
> > > A valid variable name starts with a letter or underscore
> >
> > If I am not mistaken, $_1 is not a valid variable name.
> 
> 
> You are mistaken. Try it.
> 
> -Stuart
> 

You're right... I have like 100 php scripts open in my Komodo IDE, and I
tried it before I posted out of curiosity.  I put it in the wrong
script, therefore, when it didn't do anything I assumed it didn't work.

Thanks Stuart, for pointing that out!  I've never used a number as the
first character after the $_, and I still probably never will... force
of habit I guess :)

Steve.


--- End Message ---
--- Begin Message ---
On 14 July 2011 13:37, Steve Staples <sstap...@mnsi.net> wrote:
>> A valid variable name starts with a letter or underscore
>
> If I am not mistaken, $_1 is not a valid variable name.

[2011-07-14 13:19:18] [Z:\] [\\richardquadling\scratch$ ] >php -r "$_1
= 'one'; echo $_1;"
one

It starts with an undercore and is, therefore, just fine!

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--- End Message ---
--- Begin Message ---
On Wed, Jul 13, 2011 at 16:57, Tim Streater <timstrea...@greenbee.net> wrote:
> Looking over the definition of a function today I see:
>
>    Function names follow the same rules as other labels in PHP.
>
> but I can't find the definition of a label anywhere. I can't see it listed in 
> the contents - have I overlooked it? If not, how can I request the the doccy 
> be updated?

    In this context, a label refers to the human-readable text
referencing the underlying bits and bytes.  Variables, function names,
class definitions, et cetera, are all considered labels, or - in
another way of explaining it - an alias to the corresponding program
address.

    The second part of your message is simple: look at the top-right
section of any document entry and you'll see, just to the left of the
"last updated" string, an [edit] link.  Click that, and you're on your
way.  The documentation won't update immediately, and your changes
will have to be reviewed by someone here on the Docs team, of course,
but you're certainly welcome - and encouraged - to contribute if you'd
like.

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

--- End Message ---
--- Begin Message ---
> 4 - And just found it. WordPad comes with Windows, so, maybe
> PHP+COM+WordPad
> (http://msdn.microsoft.com/en-us/library/51y8h3tk(v=vs.80).aspx) could
> be another option here. I think WordPad is just a visual wrapper for
> the RichEdit20 ActiveX component which is controllable via COM.
>
> By using templates, you could create appropriate files manually in
> WordPad and then just do a search/replace in PHP, load into RichEdit
> and print. Theoretically, a simple process.

This is the solution I'm working with except instead of WordPad I'm
using Internet Explorer and letting it parse the HTML and print.
Required a bit of fudging around with Apache permissions on the
server, probably giving it more power than it should, but for this
project it's a one-off local-only website so it shouldn't be a
problem.

I followed the first example in this article:
http://thefrozenfire.com/2011/02/using-the-windows-com-in-php/

Marc

--- End Message ---
--- Begin Message ---
The third and hopefully final release candidate of 5.3.7 was just
released for testing and can be downloaded here:

https://downloads.php.net/ilia/php-5.3.7RC3.tar.bz2 (md5sum:
0ad46340ca3d4319ab10eac4a3978ae0)
https://downloads.php.net/ilia/php-5.3.7RC3.tar.gz (md5sum:
eab0329078f74f6c8fe5abcf6943b262)

The Windows binaries are available at: http://windows.php.net/qa/

Given the volume of fixes since RC2 it was deemed necessary to make
another to ensure that there are no regressions. The intent is that
this is the final release candidate before the final release, which if
all goes well will follow in 2 weeks. PHP 5.3.7 is focused on
improving the stability and security. To ensure that the release is
solid, please test this RC against your code base and report any
problems that you encounter.

To find out what was changed since the last release please refer to
the NEWS file found within the archive or on
http://svn.php.net/viewvc/php/php-src/tags/php_5_3_7RC3/NEWS?revision=HEAD&view=markup

Windows users please mind that we don't provide VS6 builds anymore
since PHP 5.3.6.

Ilia Alshanetsky

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

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

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

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

--- End Message ---
--- Begin Message ---
Can anyone explain this to me.

function sendEmail($uname,$subjField,$firstname,$lastname,$email, $reply,$e_cc,$e_bcc,$comments,$ip,$Date,$time){

    $uname = trim($uname);
    $subjField = trim($subjField);
    $firstname = trim($firstname);
    $lastname = trim($lastname);
    $email = trim($email);
    $reply = trim($reply);
    $e_cc = trim($e_cc);
    $e_bcc = trim($e_bcc);
    $comments = trim($comments);
    $ip = trim($ip);
    $Date = trim($Date);
    $time = trim($time);

//If I trace here email, reply and the CCs are ok

if(($firstname && strlen($firstname = trim($firstname)) > 2) && ($lastname && strlen($lastname = trim($lastname)) > 2)) {
        $fullname = $firstname." ".$lastname;
        } else {
        $fullname = "Member";
        }
        $fullname = trim($fullname);
        $To = "";
        $from = "";
        $headerTXT = "";
        $bounce_email = CO_NAME." <".BOUNCE_ADDR.">";
        $subject = $subjectField;
        $bulk = false;
    //What kind of email is being sent
    //Email exists, no Cc or Bcc
    if(!empty($email) && empty($_email_cc) && empty($_email_bcc)) {
        $To = $fullname." <".$email.">";
                $from = "Member <".$reply.">";
                $headerTXT = "New message from ".CO_NAME." member ".$uname;
                $bulk = false;
        }
    //Email empty, Cc exists no Bcc
    else if(empty($email) && !empty($e_cc) && empty($e_bcc)) {
                $To = $bounce_email;
                $from = "Member <".$reply.">";
                $headerTXT = "New message from ".CO_NAME." member ".$uname;
                $bulk = true;
        }
...

//If I trace here $To, $from have everything except the "<(anything between)>", so for instance..
$To = John Doe ;
$from = Member ;

not

$To = John Doe <j...@email.com> ;
$from = Member <mem...@company.com>;

So $email and $reply are loosing their value/scope

But the ".CO_NAME." and ".BOUNCE_ADDR." are working!?!?
This is also in a page with many other email functions just like this one and they work.
Only difference is the $To and $from are not inside an if() { statement.
How did my variables loose scope???

One other note, if I put..
$To = htmlspecialchars($fullname." <".$email.">");
then $To is correct when I trace..
$To = John Doe <j...@email.com> ;
but it wont send because the smtp mail will not send to
$To = John Doe &lt;j...@email.com&gt;

I MUST be doing something wrong.
Also, I did read about using Name <em...@email.com> but the other email functions work fine with those, so I'm not sure what's going on.
TIA,
Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--- End Message ---
--- Begin Message ---
On 07/14/2011 03:54 PM, Karl DeSaulniers wrote:
> Can anyone explain this to me.

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

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

Develop with:

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

This will tell you about all of those undefined variables.

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

--- End Message ---
--- Begin Message ---

On Jul 14, 2011, at 3:54 PM, Karl DeSaulniers wrote:

Can anyone explain this to me.

function sendEmail($uname,$subjField,$firstname,$lastname,$email, $reply,$e_cc,$e_bcc,$comments,$ip,$Date,$time){

   $uname = trim($uname);
   $subjField = trim($subjField);
   $firstname = trim($firstname);
   $lastname = trim($lastname);
   $email = trim($email);
   $reply = trim($reply);
   $e_cc = trim($e_cc);
   $e_bcc = trim($e_bcc);
   $comments = trim($comments);
   $ip = trim($ip);
   $Date = trim($Date);
   $time = trim($time);

//If I trace here email, reply and the CCs are ok

if(($firstname && strlen($firstname = trim($firstname)) > 2) && ($lastname && strlen($lastname = trim($lastname)) > 2)) {
        $fullname = $firstname." ".$lastname;
        } else {
        $fullname = "Member";
        }
        $fullname = trim($fullname);
        $To = "";
        $from = "";
        $headerTXT = "";
        $bounce_email = CO_NAME." <".BOUNCE_ADDR.">";
        $subject = $subjectField;
        $bulk = false;
   //What kind of email is being sent
   //Email exists, no Cc or Bcc
   if(!empty($email) && empty($_email_cc) && empty($_email_bcc)) {
        $To = $fullname." <".$email.">";
                $from = "Member <".$reply.">";
                $headerTXT = "New message from ".CO_NAME." member ".$uname;
                $bulk = false;
        }
   //Email empty, Cc exists no Bcc
   else if(empty($email) && !empty($e_cc) && empty($e_bcc)) {
                $To = $bounce_email;
                $from = "Member <".$reply.">";
                $headerTXT = "New message from ".CO_NAME." member ".$uname;
                $bulk = true;
        }
...

//If I trace here $To, $from have everything except the "<(anything between)>", so for instance..
$To = John Doe ;
$from = Member ;

Have you looked at the output in the page source? The <> may be getting eaten by the browser. You may want to use htmlentities on your trace output (but not the actual variables).



not

$To = John Doe <j...@email.com> ;
$from = Member <mem...@company.com>;

So $email and $reply are loosing their value/scope

But the ".CO_NAME." and ".BOUNCE_ADDR." are working!?!?

I assume these are defined constants, which don't have scope (or, perhaps more accurately, always have global scope).

This is also in a page with many other email functions just like this one and they work. Only difference is the $To and $from are not inside an if() { statement.
How did my variables loose scope???

One other note, if I put..
$To = htmlspecialchars($fullname." <".$email.">");
then $To is correct when I trace..
$To = John Doe <j...@email.com> ;
but it wont send because the smtp mail will not send to
$To = John Doe &lt;j...@email.com&gt;

I MUST be doing something wrong.
Also, I did read about using Name <em...@email.com> but the other email functions work fine with those, so I'm not sure what's going on.
TIA,
Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com



--- End Message ---
--- Begin Message ---
Lol.. thanks Shawn..
You just caught me trying to hide my actually variable names.
guess I missed some. :P
They are actually the same in my code

*blushing*

Any clue why the if(){ statement would make the variables $email and $reply loose their value?
That was the chunk of it. Thanks for the error reporting code.


Best,
Karl


On Jul 14, 2011, at 4:17 PM, Shawn McKenzie wrote:

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

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

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

Develop with:

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

This will tell you about all of those undefined variables.

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

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--- End Message ---
--- Begin Message --- I'm having a problem with a brand new installation of pmwiki. I've not encountered this before so I'm unsure why this is happening. The following two warnings are presented at the top of each page:

Warning: session_write_close() [function.session-write-close]: open(/ var/lib/php/session/sess_sh3dvs4pgiuq04vmj1tfmkqvj1, O_RDWR) failed: Permission denied (13) in/var/www/vhosts/mouseha.us/httpdocs/ pmwiki-2.2.27/pmwiki.php on line 2012

Warning: session_write_close() [function.session-write-close]: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in/var/www/ vhosts/mouseha.us/httpdocs/pmwiki-2.2.27/pmwiki.php on line 2012

There are plenty of other session files in that directory with the owner/group apache:apache. I don't know why it can't deal with this.

(Cross-posted between pmwiki-users and php-general.)

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

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

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

--- End Message ---

Reply via email to