Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Michael Shadle
On Sun, Apr 12, 2009 at 8:07 AM, Raymond Irving  wrote:

>    $html = 
> preg_replace('/<\!\[CDATA\[(.*)\]\]><\/script>/s','//',$html);

question -

the output of this would be

 right?

is the cdata truly necessary? I typically use XHTML 1.0 transitional
and I don't have problems validating.

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



[PHP] Nagios Monitoring

2009-04-13 Thread Waynn Lue
Hey guys,

I'm looking to write a nagios plugin that essentially monitors whether or
not a database query returns a value > 0 at any given point.  I was hoping
to write this in PHP, but I haven't found too many examples of Nagios
plugins in PHP (
http://www.barryodonovan.com/index.php/2007/11/02/asterisk-pri-nagios is the
best one I've found so far).  Just wondering if anyone has any experience
writing them?

Waynn


Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Michael A. Peters

Michael Shadle wrote:

On Sun, Apr 12, 2009 at 8:07 AM, Raymond Irving  wrote:


   $html = 
preg_replace('/<\!\[CDATA\[(.*)\]\]><\/script>/s','//',$html);


question -

the output of this would be

 right?

is the cdata truly necessary? I typically use XHTML 1.0 transitional
and I don't have problems validating.



The problem is that validating xhtml does not necessarily render 
properly in some browsers *cough*IE*cough*


That's why I prefer to send html 4.01 to those browsers.

Would this function work for sending html and solve the utf8 problem?

function makeHTML($document) {
   $buffer = $document->saveHTML();
   $output = html_entity_decode($buffer,ENT_QUOTES,"UTF-8");
   return $output;
   }

I'll try it and see what it does.

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



Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Michael A. Peters

Michael A. Peters wrote:



function makeHTML($document) {
   $buffer = $document->saveHTML();
   $output = html_entity_decode($buffer,ENT_QUOTES,"UTF-8");
   return $output;
   }

I'll try it and see what it does.



Huh - not tried above yet - but with

$test = $myxhtml->createElement('p','שלום');
$xmlBody->appendChild($test);

both saveXML() and saveHTML() do the right thing.

However if I have the string

שלום

and load it into a DOM -

With loadHTML() the utf8 is lost regardless of whether I use saveXML() 
or saveHTML()


With loadXML() the utf8 is preserved regardless of whether or not I use 
saveXML() or saveHTML()


php 5.2.9
libxml2 2.6.26-2.1.2.7 (CentOS 5.3)

I wonder if the real utf8 problem people experience is really with 
loadHTML() and not with saveHTML() ??


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



Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Michael A. Peters

Michael A. Peters wrote:



I wonder if the real utf8 problem people experience is really with 
loadHTML() and not with saveHTML() ??




Go to http://www.clfsrpm.net/xss/dom_script_test.php

The page was meant to test something else but enter some UTF-8 into the 
textarea (well formed xhtml) -


With IE - html 4 is the only thing it will output but with FireFox and 
Opera, by default it outputs xhtml but you can check a box to force html.


When it outputs html it uses saveHTML()
When it outputs xhtml it uses saveXML()

The source is linked there so you can see.

Anyway - it looks saveHTML() works fine with UTF8 as long as loadXML() 
was used to load the data.


I've tried both Hebrew and Polytonic Greek.
It outputs correctly regardless of html or xhtml - but only after I 
changed the code to load the textarea as xml opposed to html.


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



Re: [PHP] Nagios Monitoring

2009-04-13 Thread Yannick Mortier
2009/4/13 Waynn Lue :
> Hey guys,
>
> I'm looking to write a nagios plugin that essentially monitors whether or
> not a database query returns a value > 0 at any given point.  I was hoping
> to write this in PHP, but I haven't found too many examples of Nagios
> plugins in PHP (
> http://www.barryodonovan.com/index.php/2007/11/02/asterisk-pri-nagios is the
> best one I've found so far).  Just wondering if anyone has any experience
> writing them?
>
> Waynn
>

I'm not a nagios expert but as far as I know a plugin can be anything
executable that returns the necessary values. So basically you could
just write a php script and make it executable with

#!/path/to/php

write the script here

You can find more information how to use the php cli here:

http://php.net/features.commandline

And here you can find the needed return values:

http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN78

I hope this helps!

-- 
Currently developing a browsergame...
http://www.p-game.de
Trade - Expand - Fight

Follow me on twitter!
http://twitter.com/moortier

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



Re: [PHP] what to use instead of foreach

2009-04-13 Thread Mark Kelly
Hi.

On Sunday 12 April 2009, PJ wrote:
> foreach does not allow for different formatting for output...

[snip]

> But how do you get result1, result2 & result3 // with  at end ?

$lastIndex = count($a) - 1; // Adjust for zero-indexing.
$outputString = '';
foreach ($a as $index => $value) {
if ($index != $lastIndex) {
$outputString .= "$value, ";
} else {
$outputString = rtrim($outputString,', '); // Strip last comma.
$outputString .= " & $value";
}
}
echo $outputString;

Like that? If your array is associative you can drop the $lastIndex calc 
and adjust the loop to update a counter instead. 

HTH

Mark

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



Re: [PHP] pear mdb2 and null

2009-04-13 Thread Bastien Koert
[snip]
>> I need it to error when an attempt to create a record without setting that
>> field is attempted, but setting the field to an empty string is fine.
>>
>> Attempting to insert data without defining that field indicates there is
>> not sufficient information to create a record. Setting that field to a zero
>> length string however indicates that there is enough information to create a
>> record. Assuming that no information is the same as an zero length string is
>> not OK.
>>
>> Call it bad design if you want, by MySQL knows the difference between NULL
>> and an empty string, so should my database abstraction layer.
>>
>>
> Even if the default is set to '' - pear mdb2 refuses to do the insert.
> So it looks like pear mdb2 does not know the difference between NULL and a
> zero length string.
>
> Hopefully that is configurable somewhere.
>
  

Re: [PHP] what to use instead of foreach

2009-04-13 Thread PJ
Mark Kelly wrote:
> Hi.
>
> On Sunday 12 April 2009, PJ wrote:
>   
>> foreach does not allow for different formatting for output...
>> 
>
> [snip]
>
>   
>> But how do you get result1, result2 & result3 // with  at end ?
>> 
>
> $lastIndex = count($a) - 1; // Adjust for zero-indexing.
> $outputString = '';
> foreach ($a as $index => $value) {
> if ($index != $lastIndex) {
> $outputString .= "$value, ";
> } else {
> $outputString = rtrim($outputString,', '); // Strip last comma.
> $outputString .= " & $value";
> }
> }
> echo $outputString;
>
> Like that? If your array is associative you can drop the $lastIndex calc 
> and adjust the loop to update a counter instead. 
>
> HTH
>
> Mark
>
>   
Thanks for the suggestion, Mark. I've already experimented with count;
you're close, but there is still a small glitch and that's in count();
foreach doesn't give a damn about count so you can't use that - it is
reset once inside the foreach loop. And, the "as $index" cannot relate
to the $lastIndex because the array index (which would be the index in
the "as $index") can be any number and is not sequential. There are a
couple of other ways, one is suggested by Jim Lucas in the thread
"extract varying data from array with different formatting"; another is
to change the SELECT query to use a ranking reference - I think it may
be a bit more complex, though.
Any other thoughts? ;-)  I'll appreciate them.

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



[PHP] try - catch is not so clear to me...

2009-04-13 Thread Lamp Lists
hi to all!

actually, the statement in the Subject line is not 100% correct. I understand 
the purpose and how it works (at least I think I understand :-)) but to me it's 
so complicated way?

let's take a look in example from php.net(http://us3.php.net/try)


getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>  
I would do the same thing, I think, less complicated:



I know this is "too simple, maybe not the best example", but can somebody 
please explain "the purpose" of try/catch?

Thanks.

-LL


  

Re: [PHP] what to use instead of foreach

2009-04-13 Thread PJ
Hi Leon,
Thanks for the suggestion; I'm quite new to all this, so it's a bit
complicated for my peanut brain.
I have already tried with several count and for schemes. None work
because foreach ignores any counters once in the loop. Also, this
foreach is nested within another foreach; don't know if that affects
anything.
I'll try to understand the second suggestion using for. I'll see what
comes up.
There are actually several conditions that have to be met:
1. if only 1 author = echo "author"
2. if 2 authors = echo "author & author1"
3. if more than 2 authors = echo "author, author1, author2 & author3"
That's what makes it a "toughie"

Leon du Plessis wrote:
> You may try something basic like:
>
> $b = 1;
> foreach ($my_array as $a)
> {
> echo " $a ";
>
> //Send new line to browser
> if ($b++ == 3) { echo ""; $b = 1; }
> }
>
> Or there are some different ways to approach this also like:
> for ($a =& current($my_array); $a; $a = next($my_array))
> {
> //Format 1
> echo " $a ";
> $a = next($my_array);
>
> //Format 2
> /* you may add checks here to see if $a contains data */
> echo " ~ $a ~ "; $a = next($my_array);
>
> //Format 3 + NEW LINE
> /* you may add checks here to see if $a contains data */
> echo " ~~ $a ~~ ";
> }
>
> This way you have some added control over the iteration through the array,
> and you can play around with when & how to display what.
>
> Regards.
>
> -Original Message-
> From: PJ [mailto:af.gour...@videotron.ca]
> Sent: 12 April 2009 08:57 PM
> To: php-general@lists.php.net
> Subject: [PHP] what to use instead of foreach
>
> foreach does not allow for different formatting for output...
> What could be used as a workaround?
> example:
> echo $some_result, ""; // will print all results in 1 column
> echo $some_result, ","; // will print all results comma-separated in 1 row
>
> But how do you get result1, result2 & result3 // with  at end ?

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php

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



Re: [PHP] try - catch is not so clear to me...

2009-04-13 Thread Kyle Smith

Lamp Lists wrote:

hi to all!

actually, the statement in the Subject line is not 100% correct. I understand 
the purpose and how it works (at least I think I understand :-)) but to me it's 
so complicated way?

let's take a look in example from php.net(http://us3.php.net/try)


getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>  
I would do the same thing, I think, less complicated:




I know this is "too simple, maybe not the best example", but can somebody please explain 
"the purpose" of try/catch?

Thanks.

-LL


  
  


Your example kind of defeats the point.  The point of a try {} block is 
that it will attempt to execute code and execute catch on a true 
failure.  Your function already is protected against failure.


Consider this

$x = 0;

try {
   $y = 4 / $x;  // This will divide by zero, not good.
} catch (Exception $e) {
   echo "Error: $e"
}



More importantly, the try/catch should be in your function, not around 
the invocations of your function:


function inverse($x) {
try {
return $x/0;
} catch(Exception $e) {
return false;
}
}


Consider this also, simply echoing an error on divide by Zero might not 
be great if your function is called, say, before headers.  Throwing 
exceptions can be re-caught by executing code, which can easily avoid 
pre-header output.


Does that clear up the purpose a bit?  I'm no expert, but that's my 
understanding.


HTH,
Kyle



[PHP] Re: Suggestion on .htaccess

2009-04-13 Thread Jonesy
On Mon, 13 Apr 2009 02:13:35 +0600, 9el wrote:
> This is a .htaccess for a MU blog
> the index file is kept at :   public_html/
> And main blog is kept at: public_html/blog
>
> It is causing severe cache issue. SuperCache plugin is not working.
> The blog is running out of memory most of times and consuming huge CPU.  

> Any suggestions?

Yes.  I suggest you post this somewhere else (gmane.comp.apache.user ?) 
instead of a PHP group.


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



Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Raymond Irving


Michael,

You are absolutely right! It's loadHTML() that's causing the problems.


Best regards,
__
Raymond Irving


--- On Mon, 4/13/09, Michael A. Peters  wrote:

> From: Michael A. Peters 
> Subject: Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument
> To: "Michael Shadle" 
> Cc: "Raymond Irving" , "php-general@lists.php.net" 
> 
> Date: Monday, April 13, 2009, 5:36 AM
> Michael A. Peters wrote:
> 
> > 
> > function makeHTML($document) {
> >    $buffer = $document->saveHTML();
> >    $output =
> html_entity_decode($buffer,ENT_QUOTES,"UTF-8");
> >    return $output;
> >    }
> > 
> > I'll try it and see what it does.
> > 
> 
> Huh - not tried above yet - but with
> 
> $test = $myxhtml->createElement('p','שלום');
> $xmlBody->appendChild($test);
> 
> both saveXML() and saveHTML() do the right thing.
> 
> However if I have the string
> 
> שלום
> 
> and load it into a DOM -
> 
> With loadHTML() the utf8 is lost regardless of whether I
> use saveXML() or saveHTML()
> 
> With loadXML() the utf8 is preserved regardless of whether
> or not I use saveXML() or saveHTML()
> 
> php 5.2.9
> libxml2 2.6.26-2.1.2.7 (CentOS 5.3)
> 
> I wonder if the real utf8 problem people experience is
> really with loadHTML() and not with saveHTML() ??
>

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



Re: [PHP] try - catch is not so clear to me...

2009-04-13 Thread Lamp Lists


From: Kyle Smith 
To: Lamp Lists 
Cc: php-general@lists.php.net
Sent: Monday, April 13, 2009 9:52:36 AM
Subject: Re: [PHP] try - catch is not so clear to me...

Lamp Lists wrote: 
hi to all!

actually, the statement in the Subject line is not 100% correct. I understand 
the purpose and how it works (at least I think I understand :-)) but to me it's 
so complicated way?

let's take a look in example from php.net(http://us3.php.net/try)


getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>  
I would do the same thing, I think, less complicated:



I know this is "too simple, maybe not the best example", but can somebody 
please explain "the purpose" of try/catch?

Thanks.

-LL




Your example kind of defeats the point.  The point of a try {} block is
that it will attempt to execute code and execute catch on a true
failure.  Your function already is protected against failure.

Consider this

$x = 0;

try {
$y = 4 / $x;  // This will divide by zero, not good.
} catch (Exception $e) {
echo "Error: $e"
}



More importantly, the try/catch should be in your function, not around
the invocations of your function:

function inverse($x) {
try {
return $x/0;
} catch(Exception $e) {
return false;
}
}

Consider this also, simply echoing an error on divide by Zero might not
be great if your function is called, say, before headers.  Throwing
exceptions can be re-caught by executing code, which can easily avoid
pre-header output.

Does that clear up the purpose a bit?  I'm no expert, but that's my
understanding.

HTH,
Kyle




Yes and No...
Right now I was thinking to start using try/catch block on places where could 
be problem in my code and, if there is an error - send to myself email with 
error info.
E.g., I use right now something like this:

function send_conf_email($to, $subject, $content)
{
  $headers ="MIME-Versin: 1.0\n" .
 "Content-type: text/plain; charset=ISO-8859-1; 
format=flowed\n" .
 "Content-Transfer-Encoding: 8bit\n" .
"Reply-To: \n".
 "From: LL\n" .
 "X-Mailer: PHP" . phpversion();

mail($to, $subject, $body, $headers);
}


function send_error_email_to_admin($email)
{
$to = 'l...@yahoo.com';
$subject = '[Error Report] '.$email['subject'];
$content = $email['content'];

send_conf_email($to, $subject, $content);

}



if (!send_conf_email($to, $subject, $content))
{
   send_error_email_to_admin($subject, $content);
}


how would/should be the code by using try/catch() block? something like this:

try
{
if (!send_plain_email($this->submitted_email, $subject, $body_plain))
{
throw new Exception('Confirmation email is not sent');
}
}
catch (Exception $e)
{
send_error_email_to_admin($subject, $content . $e->getMessage());
}


there is something "fishy"
:-)

-LL


  

Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Michael Shadle

Well this is an interesting turn of events :)

We should now run over to the libxml folks and see if there is  
anything that can be done.


There *are* encoding options when you setup the domdocument so it  
seems like the options are there but not working properly for one  
reason or another.


On Apr 13, 2009, at 8:01 AM, Raymond Irving  wrote:




Michael,

You are absolutely right! It's loadHTML() that's causing the problems.


Best regards,
__
Raymond Irving


--- On Mon, 4/13/09, Michael A. Peters  wrote:


From: Michael A. Peters 
Subject: Re: [PHP] Generate XHTML (HTML compatible) Code using  
DOMDocument

To: "Michael Shadle" 
Cc: "Raymond Irving" , "php- 
gene...@lists.php.net" 

Date: Monday, April 13, 2009, 5:36 AM
Michael A. Peters wrote:



function makeHTML($document) {
$buffer = $document->saveHTML();
$output =

html_entity_decode($buffer,ENT_QUOTES,"UTF-8");

return $output;
}

I'll try it and see what it does.



Huh - not tried above yet - but with

$test = $myxhtml->createElement('p','שלום');
$xmlBody->appendChild($test);

both saveXML() and saveHTML() do the right thing.

However if I have the string

שלום

and load it into a DOM -

With loadHTML() the utf8 is lost regardless of whether I
use saveXML() or saveHTML()

With loadXML() the utf8 is preserved regardless of whether
or not I use saveXML() or saveHTML()

php 5.2.9
libxml2 2.6.26-2.1.2.7 (CentOS 5.3)

I wonder if the real utf8 problem people experience is
really with loadHTML() and not with saveHTML() ??



--
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] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Michael Shadle
I will say though this negates the reason I chose to use domdocument  
to begin with. I am feeding it snippets of HTML that usually do not  
validate and I am not sure I want to run it through tidy first to  
convert from HTML to XHTML to run the domdocument and then convert it  
back... I am essentially using this to traverse the DOM and process  
all a href and img src attributes for a link remapping job. (also  
realizing the power of php's DOM for other things I used to try tidy  
and then use simplexml when doing HTML scraping ...) but php's dom  
allows me to give it absolutely crappy HTML and it still works.


However if someone has a nice regular expression or chunk of code that  
allows you to scan a doc for a href and then replaces them in the  
proper context (not just globally) that would work too. I can't just  
blindly find urls and then replace them (although the reason for this  
escapes me right now)


On Apr 13, 2009, at 8:01 AM, Raymond Irving  wrote:




Michael,

You are absolutely right! It's loadHTML() that's causing the problems.


Best regards,
__
Raymond Irving


--- On Mon, 4/13/09, Michael A. Peters  wrote:


From: Michael A. Peters 
Subject: Re: [PHP] Generate XHTML (HTML compatible) Code using  
DOMDocument

To: "Michael Shadle" 
Cc: "Raymond Irving" , "php- 
gene...@lists.php.net" 

Date: Monday, April 13, 2009, 5:36 AM
Michael A. Peters wrote:



function makeHTML($document) {
$buffer = $document->saveHTML();
$output =

html_entity_decode($buffer,ENT_QUOTES,"UTF-8");

return $output;
}

I'll try it and see what it does.



Huh - not tried above yet - but with

$test = $myxhtml->createElement('p','שלום');
$xmlBody->appendChild($test);

both saveXML() and saveHTML() do the right thing.

However if I have the string

שלום

and load it into a DOM -

With loadHTML() the utf8 is lost regardless of whether I
use saveXML() or saveHTML()

With loadXML() the utf8 is preserved regardless of whether
or not I use saveXML() or saveHTML()

php 5.2.9
libxml2 2.6.26-2.1.2.7 (CentOS 5.3)

I wonder if the real utf8 problem people experience is
really with loadHTML() and not with saveHTML() ??



--
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] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Michael Shadle
On Mon, Apr 13, 2009 at 2:19 AM, Michael A. Peters  wrote:

> The problem is that validating xhtml does not necessarily render properly in
> some browsers *cough*IE*cough*

I've never had problems and my work is primarily around IE6 / our
corporate standards. Hell, even without a script type it still works
:)

> Would this function work for sending html and solve the utf8 problem?
>
> function makeHTML($document) {
>   $buffer = $document->saveHTML();
>   $output = html_entity_decode($buffer,ENT_QUOTES,"UTF-8");
>   return $output;
>   }
>
> I'll try it and see what it does.

this was the only workaround I received for the moment, and I was a
bit afraid it would not process the full range of utf-8; it appeared
on a quick check to work but I wanted to run it on our entire database
and then ask the native geo folks to examine it for correctness.

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



Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Raymond Irving


Hi Michael,

You migth want to check out the Raxan PDI (Programmable Document Interface) 
framework. It works like a charm iwth html snippets:

example:

$page['body']->appned('שלום');
// this will append the  to the html body

Here's the link: http://raxanpdi.com

For online examples checkout: http://raxanpdi.com/examples.html

__
Raymond Irving




--- On Mon, 4/13/09, Michael Shadle  wrote:

> From: Michael Shadle 
> Subject: Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument
> To: "Raymond Irving" 
> Cc: "php-general@lists.php.net" 
> Date: Monday, April 13, 2009, 11:34 AM
> I will say though this negates the
> reason I chose to use domdocument to begin with. I am
> feeding it snippets of HTML that usually do not validate and
> I am not sure I want to run it through tidy first to convert
> from HTML to XHTML to run the domdocument and then convert
> it back... I am essentially using this to traverse the DOM
> and process all a href and img src attributes for a link
> remapping job. (also realizing the power of php's DOM for
> other things I used to try tidy and then use simplexml when
> doing HTML scraping ...) but php's dom allows me to give it
> absolutely crappy HTML and it still works.
> 
> However if someone has a nice regular expression or chunk
> of code that allows you to scan a doc for a href and then
> replaces them in the proper context (not just globally) that
> would work too. I can't just blindly find urls and then
> replace them (although the reason for this escapes me right
> now)
> 
> On Apr 13, 2009, at 8:01 AM, Raymond Irving 
> wrote:
> 
> > 
> > 
> > Michael,
> > 
> > You are absolutely right! It's loadHTML() that's
> causing the problems.
> > 
> > 
> > Best regards,
> > __
> > Raymond Irving
> > 
> > 
> > --- On Mon, 4/13/09, Michael A. Peters 
> wrote:
> > 
> >> From: Michael A. Peters 
> >> Subject: Re: [PHP] Generate XHTML (HTML
> compatible) Code using DOMDocument
> >> To: "Michael Shadle" 
> >> Cc: "Raymond Irving" ,
> "php-general@lists.php.net"
> 
> >> Date: Monday, April 13, 2009, 5:36 AM
> >> Michael A. Peters wrote:
> >> 
> >>> 
> >>> function makeHTML($document) {
> >>>     $buffer =
> $document->saveHTML();
> >>>     $output =
> >> html_entity_decode($buffer,ENT_QUOTES,"UTF-8");
> >>>     return $output;
> >>>     }
> >>> 
> >>> I'll try it and see what it does.
> >>> 
> >> 
> >> Huh - not tried above yet - but with
> >> 
> >> $test =
> $myxhtml->createElement('p','שלום');
> >> $xmlBody->appendChild($test);
> >> 
> >> both saveXML() and saveHTML() do the right thing.
> >> 
> >> However if I have the string
> >> 
> >> שלום
> >> 
> >> and load it into a DOM -
> >> 
> >> With loadHTML() the utf8 is lost regardless of
> whether I
> >> use saveXML() or saveHTML()
> >> 
> >> With loadXML() the utf8 is preserved regardless of
> whether
> >> or not I use saveXML() or saveHTML()
> >> 
> >> php 5.2.9
> >> libxml2 2.6.26-2.1.2.7 (CentOS 5.3)
> >> 
> >> I wonder if the real utf8 problem people
> experience is
> >> really with loadHTML() and not with saveHTML() ??
> >> 
> > 
> > --
> > 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] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-13 Thread Raymond Irving

Hi Michael,

Your script works fine. The only problem I'm having is that it does not support 
html entities. 

The following code will cause the page to crash:

©

I think that's because you're using loadXML and not loadHTML.

Has anyone from the dev team contacted the libxml guys about the utf-8 issue 
with loadHTML()? 


__
Raymond Irving

--- On Mon, 4/13/09, Michael A. Peters  wrote:

> From: Michael A. Peters 
> Subject: Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument
> To: "Michael Shadle" 
> Cc: "Raymond Irving" , "php-general@lists.php.net" 
> 
> Date: Monday, April 13, 2009, 5:56 AM
> Michael A. Peters wrote:
> 
> > 
> > I wonder if the real utf8 problem people experience is
> really with loadHTML() and not with saveHTML() ??
> > 
> 
> Go to http://www.clfsrpm.net/xss/dom_script_test.php
> 
> The page was meant to test something else but enter some
> UTF-8 into the textarea (well formed xhtml) -
> 
> With IE - html 4 is the only thing it will output but with
> FireFox and Opera, by default it outputs xhtml but you can
> check a box to force html.
> 
> When it outputs html it uses saveHTML()
> When it outputs xhtml it uses saveXML()
> 
> The source is linked there so you can see.
> 
> Anyway - it looks saveHTML() works fine with UTF8 as long
> as loadXML() was used to load the data.
> 
> I've tried both Hebrew and Polytonic Greek.
> It outputs correctly regardless of html or xhtml - but only
> after I changed the code to load the textarea as xml opposed
> to html.
> 
> -- 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] try - catch is not so clear to me...

2009-04-13 Thread Lamp Lists
> 

> From: Lamp Lists 
> To: php-general@lists.php.net
> Sent: Monday, April 13, 2009 9:29:16 AM
> Subject: [PHP] try - catch is not so clear to me...
> 
>  hi to all!
> 
> actually, the statement in the Subject line is not 100% correct. I understand 
> the purpose and how it works (at least I think I understand :-)) but to me 
> it's so complicated way?
> 
> let's take a look in example from php.net(http://us3.php.net/try)
> 
> 
>  function inverse($x) {
> if (!$x) {
> throw new Exception('Division by zero.');
> }
> else return 1/$x;
> }
> 
> try {
> echo inverse(5) . "\n";
> echo inverse(0) . "\n";
> } catch (Exception $e) {
> echo 'Caught exception: ',  $e->getMessage(), "\n";
> }
> 
> // Continue execution
> echo 'Hello World';
> ?>  
> I would do the same thing, I think, less complicated:
> 
>  function inverse($x)
> {
> if (!$x) {
> echo 'Division by zero';
> }
> else return 1/$x;
> 
> }
> 
> echo inverse(5);
> echo inverse(0);
> 
> // Continue execution
> echo 'Hello world';
> ?>
> 
> I know this is "too simple, maybe not the best example", but can somebody 
> please explain "the purpose" of try/catch?
> 
> Thanks.
> 
> -LL


another example from php.net


  

compare to:


  


-LL


  

[PHP] problems with gnupg extension.

2009-04-13 Thread Ray
Hello all,

I'm trying to use the gnupg extension and I think everything is properly 
installed.

I'm just using test data. I'm encrypting and then immediately decrypting. But 
the decryption is failing with a unhelpful error message.

error message :  
Warning: gnupg::decrypt() [gnupg.decrypt]: decrypt failed in 
/path/to/test2.php on line 18 

any help or suggestions would be very much appreciated. details follow.
Ray



full output:

raw data: this is a test


encoded data:

 -BEGIN PGP MESSAGE-
Version: GnuPG v2.0.11 (FreeBSD)

hQIOA9qOyyMyQ2/bEAgArxLuVw5eShkL+/g9SCGcBm5/J1G78zrh6dWFisPFqWg1
MP3zj/QnWiD9zEtLmGJazP51pV2TpySpEbILze8sz6c/imRBYLrHhbxO6W1LJqXq
rALUPDIe4qKtM7mC+K9EdFdkYRzWxi45eTK1DQtQazhqelWIb1NuaVu8vUKk/pIy
duE0juP2j+8OHIlx36sUcATkvBO5a7Ak9tGUT5T5lRqjMzKa6TPuCsZukmVh43BG
uqpz7H83LinwOCfUnyq3R2e/vIM2cv8t7jz17acOfYslonMxNz54i8jR8COmCmLY
NhGORZUSLauyWGxAIDvkDcTFD4Jd5KxaXcMPEE7zwAf9HUWmKtqOqn825AjlBxNj
7gXEOtpsRMiYiYuISzHvitpPWXQPOPsoGnPRZZBvCNJcvAgg6hMx5c4Y7tGXTsma
2hkC9f4959kBwiGAFnQxJqz2pMDW+N3X23f+kwSrU7KoNrhnxUV1ywcUGaebwYM8
emIygCm6mS7T81JtXxhMto0sSqeE/zwHc3/03/KP57V7j2tHib4dN9ZOfB6yiubF
PIwog0JYagjOfyNdGh3vRzvcYdDOqyWMgtY6XpZJwPESJlOADHVt5n844oHthRD3
MJVjwqjEz5qQiPq+kOmd4AdkpkEkRcCweYNEXVXPxpmlrduuu8kc4wsA5v3YXZ/C
x9JNAVKW9tdPSxDoxbEKyAhVdurQAxmYe7FaCLl74lACQaUg/Otwb86pjUBesgx6
mXhQv+epG71sKY+LSDxGi8dSgbOOmfI2L09zy9XTEQ4=
=85vG
-END PGP MESSAGE-


[if this line is blank, the decrypt key should have been added correctly]]

Warning: gnupg::decrypt() [gnupg.decrypt]: decrypt failed in 
/path/to/test2.php on line 18


decoded data: 




Code:

 seterrormode(gnupg::ERROR_WARNING);
echo "raw data: $raw_data";
$gpg->addencryptkey($recipient);
$encrypted = $gpg->encrypt($raw_data);
echo "encoded data:  $encrypted";

$gpg->adddecryptkey($recipient, $passphrase);
echo $gpg -> geterror();
echo "[if this line is blank, the decrypt key should have been added 
correctly]]";
echo '';
$plaintext = $gpg->decrypt($encrypted);
echo $gpg -> geterror();
echo "decoded data:  $plaintext ";
?>

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



Re: [PHP] try - catch is not so clear to me...

2009-04-13 Thread Marc Steinert
Basically try-catch gives you the ability to handle errors outside a class or method scope, by the 
calling instance.
This comes in handy, if you are programming in an object orientated way and thus enables you to 
seperate error handling from the rest of your functionality.
Means, your methods do only the things, they are meant to do, without bothering to handling occuring 
errors.

Hope, that made things clearer.

Greetings from Germany

Marc

Lamp Lists wrote:


 hi to all!

actually, the statement in the Subject line is not 100% correct. I understand 
the purpose and how it works (at least I think I understand :-)) but to me it's 
so complicated way?




--
http://bithub.net/
Synchronize and share your files over the web for free


My Twitter feed
http://twitter.com/MarcSteinert





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



RE: [PHP] what to use instead of foreach

2009-04-13 Thread Leon du Plessis
Hi PJ, 

Ok, If I understand correctly you can attempt to alter your code as per
following example (I am breaking it down a little for readability):

a) If you only wish to output the authors, see also Mark Kelly's example,
You can simply output as many authors you have associated (you will need an
associated array!!:

Or b) I include the following alternative example:


$string_out = "":
Foreach ($my_titles as $titles)
{
   Echo "Title: $titles By:";
   Foreach($my_authors[$title] as $author)
  $string_out .= "$author, "; /* Building string */

   // Add 
   $string_out .= "";

   // Here you would replace your last comma with the "&" you want
   // There are a few ways to do this (like Mark Kelly's), but will try 
   // another way (older, maybe less complicated?).
   $final_string = substr($string_out,0,strrpos($string_out,",") - 1);
   $final_string .= " & " . 
  substr($string_out,strrpos($string_out,",") + 1);
}


So all you need is to modal your data around this, and you should be fine. 
You could construct your arrays then as follows as an example:


$my_titles = array("title1","title2");
$my_authors["title1"] = array("a someone","a notherone");
$my_authors["title2"] = array("mr. a","mr. b");
... 

and so forth...how you construct the data is then very important as you can
then later use it simplify your coding as you progress and as demonstrated
below:

In future, where the need justifies it, you can construct your array to
already contain the needed string you want to output, it may help, but you
will sometimes have the same effort in constructing the data for the arrays,
so it is up to you to decide which approach is going to be best: e.g.
$my_titles = array("title1","title2");
$my_authors["title1"] = array("a someone, a notherone & Mr. X");

Then you can simply echo the array value:
echo "$my_authors["title1"] . "";

Hope it is enough info for to work on for now!!

Have fun!
Leon

-Original Message-
From: PJ [mailto:af.gour...@videotron.ca] 
Sent: 13 April 2009 04:33 PM
To: Leon du Plessis
Cc: php-general@lists.php.net
Subject: Re: [PHP] what to use instead of foreach

Hi Leon,
Thanks for the suggestion; I'm quite new to all this, so it's a bit
complicated for my peanut brain.
I have already tried with several count and for schemes. None work
because foreach ignores any counters once in the loop. Also, this
foreach is nested within another foreach; don't know if that affects
anything.
I'll try to understand the second suggestion using for. I'll see what
comes up.
There are actually several conditions that have to be met:
1. if only 1 author = echo "author"
2. if 2 authors = echo "author & author1"
3. if more than 2 authors = echo "author, author1, author2 & author3"
That's what makes it a "toughie"

Leon du Plessis wrote:
> You may try something basic like:
>
> $b = 1;
> foreach ($my_array as $a)
> {
> echo " $a ";
>
> //Send new line to browser
> if ($b++ == 3) { echo ""; $b = 1; }
> }
>
> Or there are some different ways to approach this also like:
> for ($a =& current($my_array); $a; $a = next($my_array))
> {
> //Format 1
> echo " $a ";
> $a = next($my_array);
>
> //Format 2
> /* you may add checks here to see if $a contains data */
> echo " ~ $a ~ "; $a = next($my_array);
>
> //Format 3 + NEW LINE
> /* you may add checks here to see if $a contains data */
> echo " ~~ $a ~~ ";
> }
>
> This way you have some added control over the iteration through the array,
> and you can play around with when & how to display what.
>
> Regards.
>
> -Original Message-
> From: PJ [mailto:af.gour...@videotron.ca]
> Sent: 12 April 2009 08:57 PM
> To: php-general@lists.php.net
> Subject: [PHP] what to use instead of foreach
>
> foreach does not allow for different formatting for output...
> What could be used as a workaround?
> example:
> echo $some_result, ""; // will print all results in 1 column
> echo $some_result, ","; // will print all results comma-separated in 1 row
>
> But how do you get result1, result2 & result3 // with  at end ?

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.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



RE: [PHP] what to use instead of foreach

2009-04-13 Thread Leon du Plessis
Hi PJ, 

You may want to remove the "," before the ...That was a slight oversight
on my partsorry.'bout that...I will leave you to do the fixing, but I am
sure you get the general idea.

Best wishes..Leon

-Original Message-
From: Leon du Plessis [mailto:l...@dsgnit.com] 
Sent: 13 April 2009 06:48 PM
To: 'PJ'
Cc: php-general@lists.php.net
Subject: RE: [PHP] what to use instead of foreach

Hi PJ, 

Ok, If I understand correctly you can attempt to alter your code as per
following example (I am breaking it down a little for readability):

a) If you only wish to output the authors, see also Mark Kelly's example,
You can simply output as many authors you have associated (you will need an
associated array!!:

Or b) I include the following alternative example:


$string_out = "":
Foreach ($my_titles as $titles)
{
   Echo "Title: $titles By:";
   Foreach($my_authors[$title] as $author)
  $string_out .= "$author, "; /* Building string */

   // Add 
   $string_out .= "";

   // Here you would replace your last comma with the "&" you want
   // There are a few ways to do this (like Mark Kelly's), but will try 
   // another way (older, maybe less complicated?).
   $final_string = substr($string_out,0,strrpos($string_out,",") - 1);
   $final_string .= " & " . 
  substr($string_out,strrpos($string_out,",") + 1);
}


So all you need is to modal your data around this, and you should be fine. 
You could construct your arrays then as follows as an example:


$my_titles = array("title1","title2");
$my_authors["title1"] = array("a someone","a notherone");
$my_authors["title2"] = array("mr. a","mr. b");
... 

and so forth...how you construct the data is then very important as you can
then later use it simplify your coding as you progress and as demonstrated
below:

In future, where the need justifies it, you can construct your array to
already contain the needed string you want to output, it may help, but you
will sometimes have the same effort in constructing the data for the arrays,
so it is up to you to decide which approach is going to be best: e.g.
$my_titles = array("title1","title2");
$my_authors["title1"] = array("a someone, a notherone & Mr. X");

Then you can simply echo the array value:
echo "$my_authors["title1"] . "";

Hope it is enough info for to work on for now!!

Have fun!
Leon

-Original Message-
From: PJ [mailto:af.gour...@videotron.ca] 
Sent: 13 April 2009 04:33 PM
To: Leon du Plessis
Cc: php-general@lists.php.net
Subject: Re: [PHP] what to use instead of foreach

Hi Leon,
Thanks for the suggestion; I'm quite new to all this, so it's a bit
complicated for my peanut brain.
I have already tried with several count and for schemes. None work
because foreach ignores any counters once in the loop. Also, this
foreach is nested within another foreach; don't know if that affects
anything.
I'll try to understand the second suggestion using for. I'll see what
comes up.
There are actually several conditions that have to be met:
1. if only 1 author = echo "author"
2. if 2 authors = echo "author & author1"
3. if more than 2 authors = echo "author, author1, author2 & author3"
That's what makes it a "toughie"

Leon du Plessis wrote:
> You may try something basic like:
>
> $b = 1;
> foreach ($my_array as $a)
> {
> echo " $a ";
>
> //Send new line to browser
> if ($b++ == 3) { echo ""; $b = 1; }
> }
>
> Or there are some different ways to approach this also like:
> for ($a =& current($my_array); $a; $a = next($my_array))
> {
> //Format 1
> echo " $a ";
> $a = next($my_array);
>
> //Format 2
> /* you may add checks here to see if $a contains data */
> echo " ~ $a ~ "; $a = next($my_array);
>
> //Format 3 + NEW LINE
> /* you may add checks here to see if $a contains data */
> echo " ~~ $a ~~ ";
> }
>
> This way you have some added control over the iteration through the array,
> and you can play around with when & how to display what.
>
> Regards.
>
> -Original Message-
> From: PJ [mailto:af.gour...@videotron.ca]
> Sent: 12 April 2009 08:57 PM
> To: php-general@lists.php.net
> Subject: [PHP] what to use instead of foreach
>
> foreach does not allow for different formatting for output...
> What could be used as a workaround?
> example:
> echo $some_result, ""; // will print all results in 1 column
> echo $some_result, ","; // will print all results comma-separated in 1 row
>
> But how do you get result1, result2 & result3 // with  at end ?

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] what to use instead of foreach

2009-04-13 Thread PJ
Hi Leon & thanks.
It sure is complicated. Jim Lucas example did the trick very nicely (in
my other post -
"extract varying data from array with different formatting" but here I
am learning about other ways & means.
Redoing the arrays means redoing the queries :-(  but I'll have a go at
it if I'm to learn anything. I already have a ranking column set up but
am not using it at the moment for the author display. Anyway, I have
enough to keep my neurons busy for a while.
Thanks.

Leon du Plessis wrote:
> Hi PJ,
>
> You may want to remove the "," before the ...That was a slight
> oversight
> on my partsorry.'bout that...I will leave you to do the fixing,
> but I am
> sure you get the general idea.
>
> Best wishes..Leon
>
> -Original Message-
> From: Leon du Plessis [mailto:l...@dsgnit.com]
> Sent: 13 April 2009 06:48 PM
> To: 'PJ'
> Cc: php-general@lists.php.net
> Subject: RE: [PHP] what to use instead of foreach
>
> Hi PJ,
>
> Ok, If I understand correctly you can attempt to alter your code as per
> following example (I am breaking it down a little for readability):
>
> a) If you only wish to output the authors, see also Mark Kelly's example,
> You can simply output as many authors you have associated (you will
> need an
> associated array!!:
>
> Or b) I include the following alternative example:
>
> 
> $string_out = "":
> Foreach ($my_titles as $titles)
> {
> Echo "Title: $titles By:";
> Foreach($my_authors[$title] as $author)
> $string_out .= "$author, "; /* Building string */
>
> // Add 
> $string_out .= "";
>
> // Here you would replace your last comma with the "&" you want
> // There are a few ways to do this (like Mark Kelly's), but will try
> // another way (older, maybe less complicated?).
> $final_string = substr($string_out,0,strrpos($string_out,",") - 1);
> $final_string .= " & " .
> substr($string_out,strrpos($string_out,",") + 1);
> }
> 
>
> So all you need is to modal your data around this, and you should be
> fine.
> You could construct your arrays then as follows as an example:
>
> 
> $my_titles = array("title1","title2");
> $my_authors["title1"] = array("a someone","a notherone");
> $my_authors["title2"] = array("mr. a","mr. b");
> ...
>
> and so forth...how you construct the data is then very important as
> you can
> then later use it simplify your coding as you progress and as demonstrated
> below:
>
> In future, where the need justifies it, you can construct your array to
> already contain the needed string you want to output, it may help, but you
> will sometimes have the same effort in constructing the data for the
> arrays,
> so it is up to you to decide which approach is going to be best: e.g.
> $my_titles = array("title1","title2");
> $my_authors["title1"] = array("a someone, a notherone & Mr. X");
>
> Then you can simply echo the array value:
> echo "$my_authors["title1"] . "";
>
> Hope it is enough info for to work on for now!!
>
> Have fun!
> Leon
>
> -Original Message-
> From: PJ [mailto:af.gour...@videotron.ca]
> Sent: 13 April 2009 04:33 PM
> To: Leon du Plessis
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] what to use instead of foreach
>
> Hi Leon,
> Thanks for the suggestion; I'm quite new to all this, so it's a bit
> complicated for my peanut brain.
> I have already tried with several count and for schemes. None work
> because foreach ignores any counters once in the loop. Also, this
> foreach is nested within another foreach; don't know if that affects
> anything.
> I'll try to understand the second suggestion using for. I'll see what
> comes up.
> There are actually several conditions that have to be met:
> 1. if only 1 author = echo "author"
> 2. if 2 authors = echo "author & author1"
> 3. if more than 2 authors = echo "author, author1, author2 & author3"
> That's what makes it a "toughie"
>
> Leon du Plessis wrote:
>> You may try something basic like:
>>
>> $b = 1;
>> foreach ($my_array as $a)
>> {
>> echo " $a ";
>>
>> //Send new line to browser
>> if ($b++ == 3) { echo ""; $b = 1; }
>> }
>>
>> Or there are some different ways to approach this also like:
>> for ($a =& current($my_array); $a; $a = next($my_array))
>> {
>> //Format 1
>> echo " $a ";
>> $a = next($my_array);
>>
>> //Format 2
>> /* you may add checks here to see if $a contains data */
>> echo " ~ $a ~ "; $a = next($my_array);
>>
>> //Format 3 + NEW LINE
>> /* you may add checks here to see if $a contains data */
>> echo " ~~ $a ~~ ";
>> }
>>
>> This way you have some added control over the iteration through the
>> array,
>> and you can play around with when & how to display what.
>>
>> Regards.
>>
>> -Original Message-
>> From: PJ [mailto:af.gour...@videotron.ca]
>> Sent: 12 April 2009 08:57 PM
>> To: php-general@lists.php.net
>> Subject: [PHP] what to use instead of foreach
>>
>> foreach does not allow for different formatting for output...
>> What could be used as a workaround?
>> example:
>> echo $some_result, ""; // will print all results in 1 column
>> echo

Re: [PHP] what to use instead of foreach

2009-04-13 Thread Nitsan Bin-Nun
var_dump(implode("", $array) . "");

On Mon, Apr 13, 2009 at 7:07 PM, PJ  wrote:

> Hi Leon & thanks.
> It sure is complicated. Jim Lucas example did the trick very nicely (in
> my other post -
> "extract varying data from array with different formatting" but here I
> am learning about other ways & means.
> Redoing the arrays means redoing the queries :-(  but I'll have a go at
> it if I'm to learn anything. I already have a ranking column set up but
> am not using it at the moment for the author display. Anyway, I have
> enough to keep my neurons busy for a while.
> Thanks.
>
> Leon du Plessis wrote:
> > Hi PJ,
> >
> > You may want to remove the "," before the ...That was a slight
> > oversight
> > on my partsorry.'bout that...I will leave you to do the fixing,
> > but I am
> > sure you get the general idea.
> >
> > Best wishes..Leon
> >
> > -Original Message-
> > From: Leon du Plessis [mailto:l...@dsgnit.com]
> > Sent: 13 April 2009 06:48 PM
> > To: 'PJ'
> > Cc: php-general@lists.php.net
> > Subject: RE: [PHP] what to use instead of foreach
> >
> > Hi PJ,
> >
> > Ok, If I understand correctly you can attempt to alter your code as per
> > following example (I am breaking it down a little for readability):
> >
> > a) If you only wish to output the authors, see also Mark Kelly's example,
> > You can simply output as many authors you have associated (you will
> > need an
> > associated array!!:
> >
> > Or b) I include the following alternative example:
> >
> > 
> > $string_out = "":
> > Foreach ($my_titles as $titles)
> > {
> > Echo "Title: $titles By:";
> > Foreach($my_authors[$title] as $author)
> > $string_out .= "$author, "; /* Building string */
> >
> > // Add 
> > $string_out .= "";
> >
> > // Here you would replace your last comma with the "&" you want
> > // There are a few ways to do this (like Mark Kelly's), but will try
> > // another way (older, maybe less complicated?).
> > $final_string = substr($string_out,0,strrpos($string_out,",") - 1);
> > $final_string .= " & " .
> > substr($string_out,strrpos($string_out,",") + 1);
> > }
> > 
> >
> > So all you need is to modal your data around this, and you should be
> > fine.
> > You could construct your arrays then as follows as an example:
> >
> > 
> > $my_titles = array("title1","title2");
> > $my_authors["title1"] = array("a someone","a notherone");
> > $my_authors["title2"] = array("mr. a","mr. b");
> > ...
> >
> > and so forth...how you construct the data is then very important as
> > you can
> > then later use it simplify your coding as you progress and as
> demonstrated
> > below:
> >
> > In future, where the need justifies it, you can construct your array to
> > already contain the needed string you want to output, it may help, but
> you
> > will sometimes have the same effort in constructing the data for the
> > arrays,
> > so it is up to you to decide which approach is going to be best: e.g.
> > $my_titles = array("title1","title2");
> > $my_authors["title1"] = array("a someone, a notherone & Mr. X");
> >
> > Then you can simply echo the array value:
> > echo "$my_authors["title1"] . "";
> >
> > Hope it is enough info for to work on for now!!
> >
> > Have fun!
> > Leon
> >
> > -Original Message-
> > From: PJ [mailto:af.gour...@videotron.ca]
> > Sent: 13 April 2009 04:33 PM
> > To: Leon du Plessis
> > Cc: php-general@lists.php.net
> > Subject: Re: [PHP] what to use instead of foreach
> >
> > Hi Leon,
> > Thanks for the suggestion; I'm quite new to all this, so it's a bit
> > complicated for my peanut brain.
> > I have already tried with several count and for schemes. None work
> > because foreach ignores any counters once in the loop. Also, this
> > foreach is nested within another foreach; don't know if that affects
> > anything.
> > I'll try to understand the second suggestion using for. I'll see what
> > comes up.
> > There are actually several conditions that have to be met:
> > 1. if only 1 author = echo "author"
> > 2. if 2 authors = echo "author & author1"
> > 3. if more than 2 authors = echo "author, author1, author2 & author3"
> > That's what makes it a "toughie"
> >
> > Leon du Plessis wrote:
> >> You may try something basic like:
> >>
> >> $b = 1;
> >> foreach ($my_array as $a)
> >> {
> >> echo " $a ";
> >>
> >> //Send new line to browser
> >> if ($b++ == 3) { echo ""; $b = 1; }
> >> }
> >>
> >> Or there are some different ways to approach this also like:
> >> for ($a =& current($my_array); $a; $a = next($my_array))
> >> {
> >> //Format 1
> >> echo " $a ";
> >> $a = next($my_array);
> >>
> >> //Format 2
> >> /* you may add checks here to see if $a contains data */
> >> echo " ~ $a ~ "; $a = next($my_array);
> >>
> >> //Format 3 + NEW LINE
> >> /* you may add checks here to see if $a contains data */
> >> echo " ~~ $a ~~ ";
> >> }
> >>
> >> This way you have some added control over the iteration through the
> >> array,
> >> and you can play around with when & how to display what.
> >>
> >> Regards.
> >

RE: [PHP] try - catch is not so clear to me...

2009-04-13 Thread Bob McConnell
From: Marc Steinert

> Basically try-catch gives you the ability to handle errors
> outside a class or method scope, by the 
> calling instance.
> This comes in handy, if you are programming in an object
> orientated way and thus enables you to 
> seperate error handling from the rest of your functionality.
> Means, your methods do only the things, they are meant to do,
> without bothering to handling occuring 
> errors.
> Hope, that made things clearer.

You know, this is the first explanation of exceptions I have seen that
actually makes sense. I could never figure out what they were and why
they were. It always looked like it was just a special subset of errors,
a distinction without a difference, as it were. But looking at them as a
technique to move the handlers out of the mainline code actually shines
some real light on the subject.

Thank you,

Bob McConnell

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



[PHP] multi-dimensional arrays

2009-04-13 Thread Andres Gonzalez

Hi,

I am learning PHP and have a simple question.
I have a input string in this form:

xxx    xx  x  xx   xxx
xx  x   x  xxx  xx  xx
.
.
.
xx  xxx  xx    xx   xx

each line has 6 words of various lengths, all separated by white space.
the input string can have any number of lines

I want to put this into a multi-dimensional array, each line an array 
that is an element of an outer array.


I have tried various ways to do this--I have used explode() and 
array_filter() and can get a single line parsed and into an array but I 
am having problems getting a well formed 2 dim array.


What is the easiest way to do this? With all of the PHP array functions, 
there should be an very straight forward way to do this.


Any help would be appreciated.

-Andres




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



Re: [PHP] multi-dimensional arrays

2009-04-13 Thread Shawn McKenzie
Nitsan Bin-Nun wrote:
> $string = "xxx    xx  x  xx   xxx
> xxx    xx  x  xx   xxx";
> $t = explode("\n", $string);
> foreach ($t as $k => $v) $t[$k] = explode(" ", $v);
> var_dump($t);
> 
> On Mon, Apr 13, 2009 at 8:55 PM, Andres Gonzalez 
> wrote:
> 
>> Hi,
>>
>> I am learning PHP and have a simple question.
>> I have a input string in this form:
>>
>> xxx    xx  x  xx   xxx
>> xx  x   x  xxx  xx  xx
>>.
>>.
>>.
>> xx  xxx  xx    xx   xx
>>
>> each line has 6 words of various lengths, all separated by white space.
>> the input string can have any number of lines
>>
>> I want to put this into a multi-dimensional array, each line an array that
>> is an element of an outer array.
>>
>> I have tried various ways to do this--I have used explode() and
>> array_filter() and can get a single line parsed and into an array but I am
>> having problems getting a well formed 2 dim array.
>>
>> What is the easiest way to do this? With all of the PHP array functions,
>> there should be an very straight forward way to do this.
>>
>> Any help would be appreciated.
>>
>> -Andres
>>
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> 

Well in your approach you get a bunch of empty elements where the spaces
are.  Here are two ways but I'm sure one preg_match_all() without the
explodes and loop could do it (some guru will show us):

//one way
$text = 'xxx    xx  x  xx   xxx
xx  x   x  xxx  xx  xx
xx  xxx  xx    xx   xx';

$lines = explode(PHP_EOL, $text);

foreach($lines as $line) {
$temp = explode(' ', $line);
$result[] = array_filter($temp, 'reduce');
}
function reduce($var) {
return !empty($var);
}
print_r($result);

//another way
$text = 'xxx    xx  x  xx   xxx
xx  x   x  xxx  xx  xx
xx  xxx  xx    xx   xx';

$lines = explode(PHP_EOL, $text);

foreach($lines as $line) {
preg_match_all('|([^\s]+)+|', $line, $matches);
$result[] = $matches[1];
}
print_r($result);

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

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



[PHP] Re: multi-dimensional arrays

2009-04-13 Thread Jo�o C�ndido de Souza Neto
I think the best way would be:

$arrays = explode(PHP_EOL, $field);
foreach ($arrays as &$array) {
$array = explode(" ", $array);
}

Not tested, but should work.


"Andres Gonzalez"  escreveu na mensagem 
news:49e38a9e.3090...@packetstorm.com...
> Hi,
>
> I am learning PHP and have a simple question.
> I have a input string in this form:
>
> xxx    xx  x  xx   xxx
> xx  x   x  xxx  xx  xx
> .
> .
> .
> xx  xxx  xx    xx   xx
>
> each line has 6 words of various lengths, all separated by white space.
> the input string can have any number of lines
>
> I want to put this into a multi-dimensional array, each line an array that 
> is an element of an outer array.
>
> I have tried various ways to do this--I have used explode() and 
> array_filter() and can get a single line parsed and into an array but I am 
> having problems getting a well formed 2 dim array.
>
> What is the easiest way to do this? With all of the PHP array functions, 
> there should be an very straight forward way to do this.
>
> Any help would be appreciated.
>
> -Andres
>
>
> 



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



Re: [PHP] multi-dimensional arrays

2009-04-13 Thread Shawn McKenzie
Shawn McKenzie wrote:
> Well in your approach you get a bunch of empty elements where the spaces
> are.  Here are two ways but I'm sure one preg_match_all() without the
> explodes and loop could do it (some guru will show us):
> 
> //one way
> $text = 'xxx    xx  x  xx   xxx
> xx  x   x  xxx  xx  xx
> xx  xxx  xx    xx   xx';
> 
> $lines = explode(PHP_EOL, $text);
> 
> foreach($lines as $line) {
>   $temp = explode(' ', $line);
>   $result[] = array_filter($temp, 'reduce');
> }
> function reduce($var) {
>   return !empty($var);
> }
> print_r($result);
Array
(
[0] => Array
(
[0] => xxx
[2] => 
[4] => xx
[6] => x
[8] => xx
[11] => xxx
)

[1] => Array
(
[0] => xx
[2] => x
[5] => x
[7] => xxx
[9] => xx
[11] => xx
)

[2] => Array
(
[0] => xx
[2] => xxx
[4] => xx
[6] => 
[8] => xx
[11] => xx
)

)
> 
> //another way
> $text = 'xxx    xx  x  xx   xxx
> xx  x   x  xxx  xx  xx
> xx  xxx  xx    xx   xx';
> 
> $lines = explode(PHP_EOL, $text);
> 
> foreach($lines as $line) {
>   preg_match_all('|([^\s]+)+|', $line, $matches);
>   $result[] = $matches[1];
> }
> print_r($result);
Array
(
[0] => Array
(
[0] => xxx
[1] => 
[2] => xx
[3] => x
[4] => xx
[5] => xxx
)

[1] => Array
(
[0] => xx
[1] => x
[2] => x
[3] => xxx
[4] => xx
[5] => xx
)

[2] => Array
(
[0] => xx
[1] => xxx
[2] => xx
[3] => 
[4] => xx
[5] => xx
)

)

There is a difference in the key numbering though if that is important.

-- 
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] multi-dimensional arrays

2009-04-13 Thread Andres Gonzalez

I was having the same problem. The second way was what I was looking for.

Thank you so much for your help--I did not know about preg_match_all().

very coolthanks again.

-Andres


Shawn McKenzie wrote:

Shawn McKenzie wrote:
  

Well in your approach you get a bunch of empty elements where the spaces
are.  Here are two ways but I'm sure one preg_match_all() without the
explodes and loop could do it (some guru will show us):

//one way
$text = 'xxx    xx  x  xx   xxx
xx  x   x  xxx  xx  xx
xx  xxx  xx    xx   xx';

$lines = explode(PHP_EOL, $text);

foreach($lines as $line) {
$temp = explode(' ', $line);
$result[] = array_filter($temp, 'reduce');
}
function reduce($var) {
return !empty($var);
}
print_r($result);


Array
(
[0] => Array
(
[0] => xxx
[2] => 
[4] => xx
[6] => x
[8] => xx
[11] => xxx
)

[1] => Array
(
[0] => xx
[2] => x
[5] => x
[7] => xxx
[9] => xx
[11] => xx
)

[2] => Array
(
[0] => xx
[2] => xxx
[4] => xx
[6] => 
[8] => xx
[11] => xx
)

)
  

//another way
$text = 'xxx    xx  x  xx   xxx
xx  x   x  xxx  xx  xx
xx  xxx  xx    xx   xx';

$lines = explode(PHP_EOL, $text);

foreach($lines as $line) {
preg_match_all('|([^\s]+)+|', $line, $matches);
$result[] = $matches[1];
}
print_r($result);


Array
(
[0] => Array
(
[0] => xxx
[1] => 
[2] => xx
[3] => x
[4] => xx
[5] => xxx
)

[1] => Array
(
[0] => xx
[1] => x
[2] => x
[3] => xxx
[4] => xx
[5] => xx
)

[2] => Array
(
[0] => xx
[1] => xxx
[2] => xx
[3] => 
[4] => xx
[5] => xx
)

)

There is a difference in the key numbering though if that is important.

  


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



Re: [PHP] multi-dimensional arrays

2009-04-13 Thread Nitsan Bin-Nun
$string = "xxx    xx  x  xx   xxx
xxx    xx  x  xx   xxx";
$t = explode("\n", $string);
foreach ($t as $k => $v) $t[$k] = explode(" ", $v);
var_dump($t);

On Mon, Apr 13, 2009 at 8:55 PM, Andres Gonzalez wrote:

> Hi,
>
> I am learning PHP and have a simple question.
> I have a input string in this form:
>
> xxx    xx  x  xx   xxx
> xx  x   x  xxx  xx  xx
>.
>.
>.
> xx  xxx  xx    xx   xx
>
> each line has 6 words of various lengths, all separated by white space.
> the input string can have any number of lines
>
> I want to put this into a multi-dimensional array, each line an array that
> is an element of an outer array.
>
> I have tried various ways to do this--I have used explode() and
> array_filter() and can get a single line parsed and into an array but I am
> having problems getting a well formed 2 dim array.
>
> What is the easiest way to do this? With all of the PHP array functions,
> there should be an very straight forward way to do this.
>
> Any help would be appreciated.
>
> -Andres
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] multi-dimensional arrays

2009-04-13 Thread Nitsan Bin-Nun
Just wondering, there is callback version of preg_match_all() ? if so you
could have done it in one line I think..

On Mon, Apr 13, 2009 at 9:52 PM, Andres Gonzalez wrote:

> I was having the same problem. The second way was what I was looking for.
>
> Thank you so much for your help--I did not know about preg_match_all().
>
> very coolthanks again.
>
> -Andres
>
>
>
> Shawn McKenzie wrote:
>
>> Shawn McKenzie wrote:
>>
>>
>>> Well in your approach you get a bunch of empty elements where the spaces
>>> are.  Here are two ways but I'm sure one preg_match_all() without the
>>> explodes and loop could do it (some guru will show us):
>>>
>>> //one way
>>> $text = 'xxx    xx  x  xx   xxx
>>> xx  x   x  xxx  xx  xx
>>> xx  xxx  xx    xx   xx';
>>>
>>> $lines = explode(PHP_EOL, $text);
>>>
>>> foreach($lines as $line) {
>>>$temp = explode(' ', $line);
>>>$result[] = array_filter($temp, 'reduce');
>>> }
>>> function reduce($var) {
>>>return !empty($var);
>>> }
>>> print_r($result);
>>>
>>>
>> Array
>> (
>>[0] => Array
>>(
>>[0] => xxx
>>[2] => 
>>[4] => xx
>>[6] => x
>>[8] => xx
>>[11] => xxx
>>)
>>
>>[1] => Array
>>(
>>[0] => xx
>>[2] => x
>>[5] => x
>>[7] => xxx
>>[9] => xx
>>[11] => xx
>>)
>>
>>[2] => Array
>>(
>>[0] => xx
>>[2] => xxx
>>[4] => xx
>>[6] => 
>>[8] => xx
>>[11] => xx
>>)
>>
>> )
>>
>>
>>> //another way
>>> $text = 'xxx    xx  x  xx   xxx
>>> xx  x   x  xxx  xx  xx
>>> xx  xxx  xx    xx   xx';
>>>
>>> $lines = explode(PHP_EOL, $text);
>>>
>>> foreach($lines as $line) {
>>>preg_match_all('|([^\s]+)+|', $line, $matches);
>>>$result[] = $matches[1];
>>> }
>>> print_r($result);
>>>
>>>
>> Array
>> (
>>[0] => Array
>>(
>>[0] => xxx
>>[1] => 
>>[2] => xx
>>[3] => x
>>[4] => xx
>>[5] => xxx
>>)
>>
>>[1] => Array
>>(
>>[0] => xx
>>[1] => x
>>[2] => x
>>[3] => xxx
>>[4] => xx
>>[5] => xx
>>)
>>
>>[2] => Array
>>(
>>[0] => xx
>>[1] => xxx
>>[2] => xx
>>[3] => 
>>[4] => xx
>>[5] => xx
>>)
>>
>> )
>>
>> There is a difference in the key numbering though if that is important.
>>
>>
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


[PHP] use bundled pcre in php 5.2.9 w/ apache 2.2?

2009-04-13 Thread Tom Worster
upgrading to 5.2.9 on freebsd using the ports, the question was asked:

  Use BUNDLED_PCRE (Select if you use apache 2.0.x) - Y/N?

i use apache 2.2.x so i'd guess the answer would be no. but i'm not sure.



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



Re: [PHP] multi-dimensional arrays

2009-04-13 Thread Michael A. Peters

Nitsan Bin-Nun wrote:

$string = "xxx    xx  x  xx   xxx
xxx    xx  x  xx   xxx";
$t = explode("\n", $string);
foreach ($t as $k => $v) $t[$k] = explode(" ", $v);
var_dump($t);


After assigning the string do

$string = preg_replace('/\s+/',' ',$string);

Then you should be able to do the two explodes.

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



RE: [PHP] $_GET verses $_POST

2009-04-13 Thread Daevid Vincent
Just to clarify. Obfuscation is NOT a substitute for security. While I don't
disagree with the "when's" here of GET vs POST, this statement is a bit
misleading... 

Any cracker worth his salt can easily install any number of Firefox
extensions or unix command line tools and not only view the POST data, but
alter it as well. So if you are sending something like a password, don't
think that it's "secure" just because Joe Average doesn't see it. If you're
not using SSL, then it is sent as plain text like everything else.

And don't assume that what you presented on a web page in select boxes and
other form elements is the ONLY thing that is going to come back to your
server to process. It's trivial to mangle the data. This is what SQL
injection is all about.
http://en.wikipedia.org/wiki/SQL_injection
http://phpsec.org/projects/guide/3.html

Daevid.
http://daevid.com

-Original Message-
From: Jason Pruim [mailto:ja...@jasonpruim.com] 
Sent: Sunday, April 12, 2009 12:57 PM
Subject: Re: [PHP] $_GET verses $_POST

POST does not display anything in the browser, so as others have said it's
perfect for login's since that info will never be visible to the user.
  


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



Re: [PHP] $_GET verses $_POST

2009-04-13 Thread Michael A. Peters

Daevid Vincent wrote:

Just to clarify. Obfuscation is NOT a substitute for security. While I don't
disagree with the "when's" here of GET vs POST, this statement is a bit
misleading... 


Any cracker worth his salt can easily install any number of Firefox
extensions or unix command line tools and not only view the POST data, but
alter it as well. So if you are sending something like a password, don't
think that it's "secure" just because Joe Average doesn't see it. If you're
not using SSL, then it is sent as plain text like everything else.

And don't assume that what you presented on a web page in select boxes and
other form elements is the ONLY thing that is going to come back to your
server to process. It's trivial to mangle the data. This is what SQL
injection is all about.
http://en.wikipedia.org/wiki/SQL_injection
http://phpsec.org/projects/guide/3.html

Daevid.
http://daevid.com


It also should be noted that post is not automatically secure against 
csrf attacks. While most csrf attacks are get, they can and do happen 
via post as well.


I agree that passwords need to be sent via SSL.
Unfortunately most users use the same login and passwords for many 
sites. So even if your site doesn't otherwise need SSL, using SSL for 
login helps protect your users.


For me the biggest advantage of post is the URLs aren't ugly.
For cases where get with a variable in the URL is useful (IE 
product=BluePhone) - I prefer to handle that via mod_rewrite.


The requests get handled by generic.php and generic.php then looks at 
what the requested URI is to figure out what otherwise would have 
specified by a get.


Just as linkable as ?get=whatever and a lot prettier for the user to 
look at in the url bar.


I think doing it that way also has search engine indexing advantages.

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



[PHP] linux console on the PHP

2009-04-13 Thread Alejandro Esteban Galvez
Hi people. If you known any method for grant access to one user to the console 
of linux, using the php, can you tell me that please? I going to try explain 
me! I need one interface PHP, and the interface must show me one linux console 
and take me the control of this console.

Excuse me, for my english, I speak little english.

Bye



---
Alejandro Esteban Galvez
Administrador de Red IPICHMC Rimed,
Radio-Aficionado CL2AEG
Linux User #472120 - http://i18n.counter.li.org/
Correo: alejan...@infomed.sld.cu
Correo y Jabber: alejan...@ipichmc.rimed.cu
www.ipichmc.rimed.cu
---





---
Red Telematica de Salud - Cuba

  CNICM - Infomed




Re: [PHP] $_GET verses $_POST

2009-04-13 Thread Tom Worster
On 4/12/09 10:23 AM, "Ron Piggott"  wrote:

> How do I know when to use $_GET verses $_POST?

i use GET when i want the user to be able to email the link to someone,
mention it on a blog or bookmark it and it will always yield the same page.

i use POST if submitting the form causes any change in the database or
session data (as required in the HTML standard) or if i want to hide the
mess of posted data from the user (they wouldn't be happy to see personal
details in the address bar after filling in, say, a user registration form).

if there's a grey area between these two, i'm not able to think of an
example just now.



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



Re: [PHP] $_GET verses $_POST

2009-04-13 Thread Tom Worster
On 4/13/09 6:47 PM, "Michael A. Peters"  wrote:

> For me the biggest advantage of post is the URLs aren't ugly.
> For cases where get with a variable in the URL is useful (IE
> product=BluePhone) - I prefer to handle that via mod_rewrite.
> 
> The requests get handled by generic.php and generic.php then looks at
> what the requested URI is to figure out what otherwise would have
> specified by a get.
> 
> Just as linkable as ?get=whatever and a lot prettier for the user to
> look at in the url bar.

now we've gotten into aesthetics.

personally, i think there's hardly anything more attractive than get
parameter values that, once urlencoded, parse as correct pcres. there's no
accounting for taste.



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



RE: [PHP] linux console on the PHP

2009-04-13 Thread dhorton
I am sorry if I don't understand quite what you are after.

Answer A:
If you want a console connection to a server (e.g. engsan01 as below), then
you could use a TELNET URL which is still supported in various browsers.
This doesn't require PHP, but could be embedded in the HTML part. 

engsan01:23

I have my telnet client as just the windows default client which doesn't
support secure connections. If you have a better SSH-aware client then perhaps
engsan01:22


Answer B:
If you want to execute commands from a web form then you presumably want
to use the "system" function with commands read from form
http://www.php.net/manual/en/function.system.php
Probably pretty insecure

Answer C:
If your client is on a local network and has X, then use system to run "xterm
-display clientip:0"
I think clientIP will be available on one of the $_ENV variables.

David

>-- Original Message --
>From: "Alejandro Esteban Galvez" 
>To: 
>Date: Mon, 13 Apr 2009 18:51:11 +0200
>Subject: [PHP] linux console on the PHP
>
>
>Hi people. If you known any method for grant access to one user to the console
>of linux, using the php, can you tell me that please? I going to try explain
>me! I need one interface PHP, and the interface must show me one linux console
>and take me the control of this console.
>
>Excuse me, for my english, I speak little english.
>
>Bye
>
>
>
>---
>Alejandro Esteban Galvez
>Administrador de Red IPICHMC Rimed,
>Radio-Aficionado CL2AEG
>Linux User #472120 - http://i18n.counter.li.org/
>Correo: alejan...@infomed.sld.cu
>Correo y Jabber: alejan...@ipichmc.rimed.cu
>www.ipichmc.rimed.cu
>---
>
>
>
>
>
>---
>Red Telematica de Salud - Cuba
>
> CNICM - Infomed
>
>


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



Re: [PHP] extract varying data from array with different formatting

2009-04-13 Thread Jim Lucas

PJ wrote:

Jim Lucas wrote:

PJ wrote:

foreach does a nice job if you want the results identical each time.
What can you use to change the formatting of the results dependent on
the number of results.
Here's an example:
foreach ( $authors[$bookID] AS $authorID => $authorData ) {
# Display the
echo "{$authorData['first_name']}
{$authorData['last_name']}\n";
}

will echo - Joe Boe John Blue Andy Candy etc depending on how many rows
we have.
What I want is: Joe Boe, John Blue, Andy Candy & Hans Stick ( separated
by commas, except for the last one which is separated with & .
I thought of passing a variable to the foreach and then using if
elseif... but that can't work because the variable is reset to 0 after
each pass.
Can't get switch to do it (maybe I don't understand it right.
Help ?


your answer lies with not replacing foreach to make your life/output
better.  But with how the data is prepared and handed off to the
foreach statement.

I am guessing that what you want would be something like this.

Since this looks like a snippet of code I sent you the other day, I
will snag it "complete" from the other thread.

 $authorData ) {
# Add all the authors to that new array
 $aList[] = "{$authorData['last_name']},
{$authorData['first_name']}";
}

# Sanitize the output
$aList = array_map('htmlspecialchars', $aList);

# Get a count of how many authors their is.
$tAuthors = count($aList);

# If more then one, do...
if ( $tAuthors > 1 ) {
# Take the last one off, so we can handle it differently
$last_author = array_pop($aList);
echo join(', ', $aList), ' & ', $last_author;

# If only one, then do...
} elseif ( $tAuthors == 1 ) {
echo join('', $aList);
}
echo '';
} else {
echo 'No authors found';
}


...

?>


Hi Jim,
Please excuse my writing to you directly. If you don't think it's
proper, just let me know & I'll swing off.


No problem with hitting me directly, but your findings could be of use to others
since it is cleaner way of solving your problem.

So, on the list we go


So, while I have your attention and if you have a moment, I found this
interesting possibility: someone threw "implode()" at me and I looked it
up in the php manual and hey, found and interesting little function:

function ImplodeProper($arr, $lastConnector = ' & ')
{
  if( !is_array($arr) or count($arr) == 0) return '';
  $last = array_pop($arr);
  if(count($arr))
return implode(', ',$arr).", $lastConnector $last";
  else
return $last;
}

Since my limited understanding of php impedes me to implement it
experimentally in my application, I was curious if, indeed, it could be
another option. It does look to me like it could work, but it would
require a slightly different implementation of the query, probably
somehow using something like a CONCAT(first_name, " ", last_name). Am I
learning something here or is this the wrong tree to bark up?



This would be a very nice way to clean up the code

Although you could do something with CONCAT(), I would suggest leaving the code 
as is.

Data is all that you want to get from MYSQL, not format.

Basically, take the above function and place it in a lib you include
for everything.  Then replace the if/then/else statement that I built for you 
with a
call to said function.

 $authorData ) {
 # Add all the authors to that new array
  $aList[] = "{$authorData['last_name']}, 
{$authorData['first_name']}";
 }

 # Sanitize the output
 $aList = array_map('htmlspecialchars', $aList);

 echo implodeProper($aList), '';

 } else {
 echo 'No authors found';
 }

...

?>

That would do the trick.

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



[PHP] Logging out of a SSL / https:// site using PHP? (or JS?), Client Side Cache

2009-04-13 Thread scubak1w1
Hello,




I have a series of web sites which use https:// authentication (using AD 
integration to 'check the credentials' as it were) - all seems to be working 
well..

I have been Googling et al. for a way to log the user off the site 
"fully"...


I can do a series of things on the server side per Dreamweaver's Server 
Behaviour / User Authentication | Log Out User, etc - but the client's 
browser cache (?) still keeps the credentials, and so ifthey return to the 
site (say, with their back button) they can get right back in... the only 
sure fire way that I can see, simply, is to close and reopen the browser.


Any thoughts on how to clear the user's browser's cache of a https:// site's 
credentials and then send them on to a non-secure page?


I thought of:




  a.. closing and reopening the browser with some JS, if this is indeed 
possible - buT I would need to somehow keep track of what other pages the 
user had open, their security settings might now allow it, the user would 
likley get annoyed, etc, etc


  b.. "forcing" a 401 or 403 - but my attempts at 'coding' this were 
unsuccessful - and also how do you get the page to redirect on to something 
like www.adobe.com or something (because seeing a 403 'standard page 
message' would likely be "alarming" to the average user


  c.. I have some code in ASP that will do this, but the user would be have 
to be limited to using Internet Destroyer  -ugh!  :-)



Thanks In Advance:

GREG...




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



[PHP] https and Credit Cards

2009-04-13 Thread Skip Evans

Hey all,

I've always put any forms that collect credit card information 
behind a secure connection, https, figuring that sending that 
information from the client browser to the server should be 
secure, but I'm having convincing a client that it is necessary.


He instead insists that only the call to the credit card 
processor's server needs to be secure and of course the 
processor supplies the connection there.


But doesn't also the form need to be secure since you're 
sending CC information from that form back to the web site's 
server?


That's what I've always assumed.

I need some opinions on this, and if I'm right I think the 
client will defer to a few more votes.


--

Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com

Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

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



Re: [PHP] try - catch is not so clear to me...

2009-04-13 Thread Lamp Lists




From: Marc Steinert 
To: Lamp Lists 
Cc: php-general@lists.php.net
Sent: Monday, April 13, 2009 11:27:08 AM
Subject: Re: [PHP] try - catch is not so clear to me...

Basically try-catch gives you the ability to handle errors outside a class or 
method scope, by the calling instance.
This comes in handy, if you are programming in an object orientated way and 
thus enables you to seperate error handling from the rest of your functionality.
Means, your methods do only the things, they are meant to do, without bothering 
to handling occuring errors.
Hope, that made things clearer.

Greetings from Germany

Marc

Lamp Lists wrote:

>>  hi to all!
>> 
>> actually, the statement in the Subject line is not 100% correct. I 
>> understand the purpose and how it works (at least I think I understand :-)) 
>> but to me it's so complicated way?
>> 


-- http://bithub.net/
Synchronize and share your files over the web for free


My Twitter feed
http://twitter.com/MarcSteinert




Looks like I still didn't get it correctly:

try
{
if (!send_confirmation_email($email, $subject, $content))
{
throw new Exception('Confirmation email is not sent');
}

}
catch (Exception $e)
{
send_email_with_error_to_admin($e, $content);
}

why am I getting both emails? I'm receiving confirmation email and email with 
error message - that I'm supposed to get if the first one is not sent for some 
reason?!?!?!?

thanks for any help.

-LL


  

Re: [PHP] https and Credit Cards

2009-04-13 Thread Paul M Foster
On Mon, Apr 13, 2009 at 10:19:34PM -0500, Skip Evans wrote:

> Hey all,
>
> I've always put any forms that collect credit card information
> behind a secure connection, https, figuring that sending that
> information from the client browser to the server should be
> secure, but I'm having convincing a client that it is necessary.
>
> He instead insists that only the call to the credit card
> processor's server needs to be secure and of course the
> processor supplies the connection there.
>
> But doesn't also the form need to be secure since you're
> sending CC information from that form back to the web site's
> server?
>
> That's what I've always assumed.
>
> I need some opinions on this, and if I'm right I think the
> client will defer to a few more votes.

You're absolutely right, no question, and for exactly the reasons you
give. The path back to the server from the client is unencrypted if you
don't use https, and the credit card information is in the clear when
transmitted.

In fact, if I were a hacker and found out that you were doing this, I'd
make it my business to hijack that connection so I could transparently
capture credit card information. I mean, for a hacker, that's just too
sweet a setup.

Incidentally, if he insists, I'd decline the job. Even if he signed
waiver after waiver to absolve you of responsibility (which I'd make him
sign), he could still go after you later when the consequences hit. Let
some less ethical coder do it the way he wants.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Logging out of a SSL / https:// site using PHP? (or JS?), Client Side Cache

2009-04-13 Thread Michael A. Peters

scubak1w1 wrote:

Hello,




I have a series of web sites which use https:// authentication (using AD 
integration to 'check the credentials' as it were) - all seems to be working 
well..


I have been Googling et al. for a way to log the user off the site 
"fully"...



I can do a series of things on the server side per Dreamweaver's Server 
Behaviour / User Authentication | Log Out User, etc - but the client's 
browser cache (?) still keeps the credentials, and so ifthey return to the 
site (say, with their back button) they can get right back in...


Sounds like you are not properly expiring the session.
The only login credentials that ever should be stored with the client is 
a session id.


Expire the session id - and the session ID in their cookie becomes 
completely meaningless.


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



Re: [PHP] $_GET verses $_POST

2009-04-13 Thread Ashley Sheridan
On Mon, 2009-04-13 at 15:47 -0700, Michael A. Peters wrote:
> Daevid Vincent wrote:
> > Just to clarify. Obfuscation is NOT a substitute for security. While I don't
> > disagree with the "when's" here of GET vs POST, this statement is a bit
> > misleading... 
> > 
> > Any cracker worth his salt can easily install any number of Firefox
> > extensions or unix command line tools and not only view the POST data, but
> > alter it as well. So if you are sending something like a password, don't
> > think that it's "secure" just because Joe Average doesn't see it. If you're
> > not using SSL, then it is sent as plain text like everything else.
> > 
> > And don't assume that what you presented on a web page in select boxes and
> > other form elements is the ONLY thing that is going to come back to your
> > server to process. It's trivial to mangle the data. This is what SQL
> > injection is all about.
> > http://en.wikipedia.org/wiki/SQL_injection
> > http://phpsec.org/projects/guide/3.html
> > 
> > Daevid.
> > http://daevid.com
> 
> It also should be noted that post is not automatically secure against 
> csrf attacks. While most csrf attacks are get, they can and do happen 
> via post as well.
> 
> I agree that passwords need to be sent via SSL.
> Unfortunately most users use the same login and passwords for many 
> sites. So even if your site doesn't otherwise need SSL, using SSL for 
> login helps protect your users.
> 
> For me the biggest advantage of post is the URLs aren't ugly.
> For cases where get with a variable in the URL is useful (IE 
> product=BluePhone) - I prefer to handle that via mod_rewrite.
> 
> The requests get handled by generic.php and generic.php then looks at 
> what the requested URI is to figure out what otherwise would have 
> specified by a get.
> 
> Just as linkable as ?get=whatever and a lot prettier for the user to 
> look at in the url bar.
> 
> I think doing it that way also has search engine indexing advantages.
> 
I've done a bit of research into that, and can't find any evidence to
suggest that the so-called "friendly URL's" are actually of any benefit
to search engines. Just put a question into Google, and more often than
not, the top few results are from forums, which tend not to use these
friendly URL's. The only reason one might help with SEO is the case
where a site is being redeveloped or re-versioned, and you need to
preserve old page names to retain any ranking the site once had.

Of course, I'm welcome for any evidence to the contrary, so if any of
you have stumbled across links to any of that...


Ash
www.ashleysheridan.co.uk


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