James Colannino | 1 Oct 05:07 2009

Converting print_r() output to an array

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

Michael Shadle | 1 Oct 05:12 2009
Picon

Re: Converting print_r() output to an array

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 <james <at> colannino.org> 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
>
>

--

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

(Continue reading)

Jonathan Tapicer | 1 Oct 05:16 2009
Picon

Re: Converting print_r() output to an array

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 <james <at> colannino.org> 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
>
>

(Continue reading)

Daniel Brown | 1 Oct 05:28 2009
Picon
Picon

Re: Converting print_r() output to an array

On Wed, Sep 30, 2009 at 23:07, James Colannino <james <at> colannino.org> 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.
*/
?>

(Continue reading)

Paul M Foster | 1 Oct 05:29 2009

POST without POSTing

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

--

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

Daniel Brown | 1 Oct 05:36 2009
Picon
Picon

Re: POST without POSTing

On Wed, Sep 30, 2009 at 23:29, Paul M Foster <paulf <at> quillandmouse.com> 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>
daniel.brown <at> parasane.net || danbrown <at> php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

--

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

Paul M Foster | 1 Oct 06:16 2009

Re: POST without POSTing

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

> On Wed, Sep 30, 2009 at 23:29, Paul M Foster <paulf <at> quillandmouse.com> 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
(Continue reading)

Daniel Brown | 1 Oct 06:24 2009
Picon
Picon

Re: POST without POSTing

On Thu, Oct 1, 2009 at 00:16, Paul M Foster <paulf <at> quillandmouse.com> 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>
daniel.brown <at> parasane.net || danbrown <at> php.net
(Continue reading)

Lars Torben Wilson | 1 Oct 06:31 2009
Picon
Picon

Re: POST without POSTing

On Thu, 1 Oct 2009 00:16:27 -0400
Paul M Foster <paulf <at> quillandmouse.com> 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
> > <paulf <at> quillandmouse.com> 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");
(Continue reading)

Paul M Foster | 1 Oct 06:41 2009

Re: POST without POSTing

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

> On Thu, Oct 1, 2009 at 00:16, Paul M Foster <paulf <at> quillandmouse.com> 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,
(Continue reading)


Gmane