php-general Digest 1 Oct 2009 12:00:39 -0000 Issue 6367

Topics (messages 298421 through 298433):

Converting print_r() output to an array
        298421 by: James Colannino
        298422 by: Michael Shadle
        298423 by: Jonathan Tapicer
        298424 by: Daniel Brown

POST without POSTing
        298425 by: Paul M Foster
        298426 by: Daniel Brown
        298427 by: Paul M Foster
        298428 by: Daniel Brown
        298429 by: Lars Torben Wilson
        298430 by: Paul M Foster
        298431 by: Daniel Brown
        298432 by: Lars Torben Wilson

Re: Self-Process php forms or not?
        298433 by: MEM

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Hey everyone, I was pretty sure there was an easy built-in solution for
what I want to do, but I've been googling around with no luck.
Basically, I just want to take a string containing the output of
print_r() and convert it back into an array again.

That is possible, right?  If so, how do I go about it?  If not, what's a
quick and easy way to parse a string and turn it into an array (I don't
necessarily need the string to be in the format print_r returns).

Thanks!

James

--- End Message ---
--- Begin Message ---
first off, if you pass print_r($var, true) it will return it instead
of printing it. if you go that route.

have you looked at var_export() ?

On Wed, Sep 30, 2009 at 8:07 PM, James Colannino <[email protected]> wrote:
> Hey everyone, I was pretty sure there was an easy built-in solution for
> what I want to do, but I've been googling around with no luck.
> Basically, I just want to take a string containing the output of
> print_r() and convert it back into an array again.
>
> That is possible, right?  If so, how do I go about it?  If not, what's a
> quick and easy way to parse a string and turn it into an array (I don't
> necessarily need the string to be in the format print_r returns).
>
> Thanks!
>
> James
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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

May be you want to take a look at serialize and unserialize functions,
serialize generates a string from a variable and then unserialize can
give you the value of the variable back from the string.

Regards,

Jonathan


On Thu, Oct 1, 2009 at 12:07 AM, James Colannino <[email protected]> wrote:
> Hey everyone, I was pretty sure there was an easy built-in solution for
> what I want to do, but I've been googling around with no luck.
> Basically, I just want to take a string containing the output of
> print_r() and convert it back into an array again.
>
> That is possible, right?  If so, how do I go about it?  If not, what's a
> quick and easy way to parse a string and turn it into an array (I don't
> necessarily need the string to be in the format print_r returns).
>
> Thanks!
>
> James
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Wed, Sep 30, 2009 at 23:07, James Colannino <[email protected]> wrote:
> Hey everyone, I was pretty sure there was an easy built-in solution for
> what I want to do, but I've been googling around with no luck.
> Basically, I just want to take a string containing the output of
> print_r() and convert it back into an array again.

    Well, print_r() simply iterates the array and prints it.... so if
you just want the array, skip print_r() entirely and use the variable
you were passing to it.

> That is possible, right?  If so, how do I go about it?  If not, what's a
> quick and easy way to parse a string and turn it into an array (I don't
> necessarily need the string to be in the format print_r returns).

    There's plenty of ways to parse strings into arrays, it just
depends on how you want to do it.  For one example, if you wanted to
split each word into an individual array value, you could do:

<?php
$sentence = "This is a test.";
$words = explode(' ',$sentence);
/*
Then $words would contain:
    [0] => This
    [1] => is
    [2] => a
    [3] => test.
*/
?>

    Then, say you wanted to shuffle the words around, and then convert
them back to an array.  I don't know why, just say it.... out loud.
I'll wait.

    Nevermind, here's the example anyway:

<?php
// From $words in the previous example....
shuffle($words);
$sentence = implode(' ',$words);
?>

    The latter example will mix up the words and put them back into a
sentence, with a whitespace (' ') as the "glue" between them.

-- 
</Daniel P. Brown>
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

--- End Message ---
--- Begin Message ---
I'm sure this has been covered before, but I'm not even sure how to
search in the archives for it.

I have a form that collects certain info via POST. It is re-entrant, so
when the user hits the "submit" button, it checks the input and does
whatever sanity checks it needs to. If all is okay, it must now pass
some of that info to another URL (offsite) via POST. Normally, the
information would be passed via a series of GET variables or SESSION
variables. But in this case the site the user is being directed to must
receive the information via POST.

I'm not sure how to do this. Please no exotic external libraries my
shared hosting provider doesn't include. RTFM will be fine; just tell me
which Fine Manual to Read.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
On Wed, Sep 30, 2009 at 23:29, Paul M Foster <[email protected]> wrote:
>
> I'm not sure how to do this. Please no exotic external libraries my
> shared hosting provider doesn't include. RTFM will be fine; just tell me
> which Fine Manual to Read.

    Nothing too exotic at all, Paul.  Check out cURL:

    http://php.net/curl

-- 
</Daniel P. Brown>
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

--- End Message ---
--- Begin Message ---
On Wed, Sep 30, 2009 at 11:36:55PM -0400, Daniel Brown wrote:

> On Wed, Sep 30, 2009 at 23:29, Paul M Foster <[email protected]> wrote:
> >
> > I'm not sure how to do this. Please no exotic external libraries my
> > shared hosting provider doesn't include. RTFM will be fine; just tell me
> > which Fine Manual to Read.
> 
>     Nothing too exotic at all, Paul.  Check out cURL:
> 
>     http://php.net/curl

I was afraid you were going to say that, and I wasn't sure cURL was
supported on that server. But I just loaded phpinfo on that server, and
it is supported.

However, assuming it *wasn't*, I've found the following example from a
google search (thank goodness for google's "hinting" or I couldn't have
found it):

$fp = fsockopen("www.site.com", 80);
fputs($fp, "POST /script.php HTTP/1.0
Host: www.site.com
Content-Length: 7

q=proxy");

I don't know much about doing things this way. It appears that when done
this way, the "body" must be separated by a newline, just like email.
And it appears that the content-length of 7 indicates the length of the
"q=proxy" string. Assuming I piled on a few other passed variables the
same way as "q", separated by newlines (and adjusted the Content-Length
accordingly), would the above work? Are there liabilities to doing it
this way?

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
On Thu, Oct 1, 2009 at 00:16, Paul M Foster <[email protected]> wrote:
>
> However, assuming it *wasn't*, I've found the following example from a
> google search (thank goodness for google's "hinting" or I couldn't have
> found it):
>
> $fp = fsockopen("www.site.com", 80);
> fputs($fp, "POST /script.php HTTP/1.0
> Host: www.site.com
> Content-Length: 7
>
> q=proxy");
>
> I don't know much about doing things this way. It appears that when done
> this way, the "body" must be separated by a newline, just like email.
> And it appears that the content-length of 7 indicates the length of the
> "q=proxy" string. Assuming I piled on a few other passed variables the
> same way as "q", separated by newlines (and adjusted the Content-Length
> accordingly), would the above work? Are there liabilities to doing it
> this way?

    Yes.  Hosts are more likely to have cURL installed and available
than fsockopen() or URL-based fopen() calls, so portability is greater
with cURL.  It's also a bit faster.  Still, as you know, there's
always more than one way to skin a cute, furry, delicious little
kitten.

-- 
</Daniel P. Brown>
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

--- End Message ---
--- Begin Message ---
On Thu, 1 Oct 2009 00:16:27 -0400
Paul M Foster <[email protected]> wrote:

> On Wed, Sep 30, 2009 at 11:36:55PM -0400, Daniel Brown wrote:
> 
> > On Wed, Sep 30, 2009 at 23:29, Paul M Foster
> > <[email protected]> wrote:
> > >
> > > I'm not sure how to do this. Please no exotic external libraries
> > > my shared hosting provider doesn't include. RTFM will be fine;
> > > just tell me which Fine Manual to Read.
> > 
> >     Nothing too exotic at all, Paul.  Check out cURL:
> > 
> >     http://php.net/curl
> 
> I was afraid you were going to say that, and I wasn't sure cURL was
> supported on that server. But I just loaded phpinfo on that server,
> and it is supported.
> 
> However, assuming it *wasn't*, I've found the following example from a
> google search (thank goodness for google's "hinting" or I couldn't
> have found it):
> 
> $fp = fsockopen("www.site.com", 80);
> fputs($fp, "POST /script.php HTTP/1.0
> Host: www.site.com
> Content-Length: 7
> 
> q=proxy");
> 
> I don't know much about doing things this way. It appears that when
> done this way, the "body" must be separated by a newline, just like
> email. And it appears that the content-length of 7 indicates the
> length of the "q=proxy" string. Assuming I piled on a few other
> passed variables the same way as "q", separated by newlines (and
> adjusted the Content-Length accordingly), would the above work? Are
> there liabilities to doing it this way?
> 
> Paul
> 

Not separated by newlines; separated by ampersands. But otherwise,
that's just raw HTTP 1.1 protocol. cURL and other tools might look a bit
more complicated at first, but (assuming they're available) they do
shield you from the raw protocol a bit. No real liability to doing it
that way other than it's a bit more work.

http://developers.sun.com/mobility/midp/ttips/HTTPPost/


Regards,

Torben

--- End Message ---
--- Begin Message ---
On Thu, Oct 01, 2009 at 12:24:41AM -0400, Daniel Brown wrote:

> On Thu, Oct 1, 2009 at 00:16, Paul M Foster <[email protected]> wrote:
> >
> > However, assuming it *wasn't*, I've found the following example from a
> > google search (thank goodness for google's "hinting" or I couldn't have
> > found it):
> >
> > $fp = fsockopen("www.site.com", 80);
> > fputs($fp, "POST /script.php HTTP/1.0
> > Host: www.site.com
> > Content-Length: 7
> >
> > q=proxy");
> >
> > I don't know much about doing things this way. It appears that when done
> > this way, the "body" must be separated by a newline, just like email.
> > And it appears that the content-length of 7 indicates the length of the
> > "q=proxy" string. Assuming I piled on a few other passed variables the
> > same way as "q", separated by newlines (and adjusted the Content-Length
> > accordingly), would the above work? Are there liabilities to doing it
> > this way?
> 
>     Yes.  Hosts are more likely to have cURL installed and available
> than fsockopen() or URL-based fopen() calls, so portability is greater
> with cURL.  It's also a bit faster.  Still, as you know, there's
> always more than one way to skin a cute, furry, delicious little
> kitten.

fsockopen() appears to be part of the standard network functions in PHP,
like the header() function. Do you mean that many hosts support the
function (as part of PHP) but don't support its use with external hosts?
Is there a way to determine this support from looking at phpinfo()?

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
On Thu, Oct 1, 2009 at 00:41, Paul M Foster <[email protected]> wrote:
>
> fsockopen() appears to be part of the standard network functions in PHP,
> like the header() function. Do you mean that many hosts support the
> function (as part of PHP) but don't support its use with external hosts?
> Is there a way to determine this support from looking at phpinfo()?

    fsockopen() is a socket function, as the name suggests.  Hosts can
disable the usage of sockets.  In fact, check Google and you'll see
several folks complaining of their host having it disabled.

    As for fopen(), there's a php.ini value `allow_url_fopen` that a
lot of hosts have set to 'no,' I'm sure with the intent to increase
security.... but when you can still use cURL and exec('wget'), it kind
of defeats the purpose.

-- 
</Daniel P. Brown>
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

--- End Message ---
--- Begin Message ---
On Thu, 1 Oct 2009 00:24:41 -0400
Daniel Brown <[email protected]> wrote:

> On Thu, Oct 1, 2009 at 00:16, Paul M Foster <[email protected]>
> wrote:
> >
> > However, assuming it *wasn't*, I've found the following example
> > from a google search (thank goodness for google's "hinting" or I
> > couldn't have found it):
> >
> > $fp = fsockopen("www.site.com", 80);
> > fputs($fp, "POST /script.php HTTP/1.0
> > Host: www.site.com
> > Content-Length: 7
> >
> > q=proxy");
> >
> > I don't know much about doing things this way. It appears that when
> > done this way, the "body" must be separated by a newline, just like
> > email. And it appears that the content-length of 7 indicates the
> > length of the "q=proxy" string. Assuming I piled on a few other
> > passed variables the same way as "q", separated by newlines (and
> > adjusted the Content-Length accordingly), would the above work? Are
> > there liabilities to doing it this way?
> 
>     Yes.  Hosts are more likely to have cURL installed and available
> than fsockopen() or URL-based fopen() calls, so portability is greater
> with cURL.  It's also a bit faster.  Still, as you know, there's
> always more than one way to skin a cute, furry, delicious little
> kitten.
> 

I stand corrected on that point--in that way, yes, it would be a
liability. Happily it's been so long since I've had to use that kind of
host that I don't usually consider that a problem. But yes, if you're
using free or low-end hosting then you might have to contend with that.
Ugly, but true.


Torben

--- End Message ---
--- Begin Message ---
One last question about this:

I've done a self submit form, after hearing all the advantages expressed
here. 
But how could we relate, without using javascript, a self submit form with a
"success page" or a "confirmation page" that doesn't show the form?

Can please someone throw me some infos about this please?


Ps- I've googled: "php redirect success page on self submit form" and
similar... 



Regards, 
Márcio

> -----Original Message-----
> From: Bob McConnell [mailto:[email protected]]
> Sent: sexta-feira, 24 de Abril de 2009 14:10
> To: PHP-General List
> Subject: RE: [PHP] Self-Process php forms or not?
> 
> When you have it all in one file, the first thing you do is check to
> see if this request was submitted from the form. If not, you send the
> blank form. If it was, you validate all of the data. When a validation
> fails, you add error messages and resend the form with any fields that
> passed the validation already filled in. When validation succeeds,
> process and move on. No muss, no fuss.
> 
> Bob McConnell
> 
> -----Original Message-----
> From: Sándor Tamás (HostWare Kft.) [mailto:[email protected]]
> Sent: Friday, April 24, 2009 8:53 AM
> To: 'PHP-General List'
> Subject: Re: [PHP] Self-Process php forms or not?
> 
> I think the main advantage is that if something goes wrong processing
> the
> datas, you can show the form again without redirecting again.
> 
> And if you have to change the behavior of the page, you have to change
> only
> one file instead of two.
> 
> SanTa
> 
> ----- Original Message -----
> From: "MEM" <[email protected]>
> To: "'PHP-General List'" <[email protected]>
> Sent: Friday, April 24, 2009 2:34 PM
> Subject: [PHP] Self-Process php forms or not?
> 
> 
> I'm trying to understand the advantages behind opting by using a
> Self-Process PHP Form, instead of having a form and then point the
> action of
> the form to another .php page.
> 
> Can anyone point me some resources about this. Why using one instead of
> another. What are the main advantages?
> 
> 
> 
> Regards,
> Márcio
> 
> 
> --
> 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


--- End Message ---

Reply via email to