Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #3188 > unrolled thread
| Started by | "eBob.com" <eBob.com@totallybogus.com> |
|---|---|
| First post | 2011-09-21 16:56 -0400 |
| Last post | 2011-09-29 09:15 -0400 |
| Articles | 9 — 7 participants |
Back to article view | Back to comp.lang.php
Names of URL Parameters "eBob.com" <eBob.com@totallybogus.com> - 2011-09-21 16:56 -0400
Re: Names of URL Parameters The Natural Philosopher <tnp@invalid.invalid> - 2011-09-21 22:06 +0100
Re: Names of URL Parameters Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-09-21 23:46 +0200
Re: Names of URL Parameters "eBob.com" <eBob.com@totallybogus.com> - 2011-09-21 23:27 -0400
Re: Names of URL Parameters "Peter H. Coffin" <hellsop@ninehells.com> - 2011-09-22 07:43 -0500
Re: Names of URL Parameters Richard Damon <news.x.richarddamon@xoxy.net> - 2011-09-22 13:36 -0400
Re: Names of URL Parameters tamouse <tamouse.lists@gmail.com> - 2011-09-28 11:46 -0700
Re: Names of URL Parameters tamouse <tamouse.lists@gmail.com> - 2011-09-28 12:18 -0700
Re: Names of URL Parameters sheldonlg <sheldonlg@thevillages.net> - 2011-09-29 09:15 -0400
| From | "eBob.com" <eBob.com@totallybogus.com> |
|---|---|
| Date | 2011-09-21 16:56 -0400 |
| Subject | Names of URL Parameters |
| Message-ID | <Qbseq.173772$wz.21080@en-nntp-08.dc1.easynews.com> |
I know that I can get and print the value of a URL parameter this way ... echo '<p>phone: ' . $_GET['phone'] . '</p>'; ... and that works fine of course. But what if I don't know the names of all the parameters and just want to print out the names and values of all the parameters? (It might not seem to make a lot of sense, but it would be useful to me in experimenting/developing/debugging.) It looks like (I haven't tried it) $_SERVER['QUERY_STRING'] would give me the entire URL but I'd really rather not have to parse it. Thanks, Bob (a very new noob)
[toc] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2011-09-21 22:06 +0100 |
| Message-ID | <j5djl1$nh0$1@news.albasani.net> |
| In reply to | #3188 |
eBob.com wrote: > I know that I can get and print the value of a URL parameter this way ... > > echo '<p>phone: ' . $_GET['phone'] . '</p>'; > > ... and that works fine of course. But what if I don't know the names > of all the parameters and just want to print out the names and values of > all the parameters? (It might not seem to make a lot of sense, but it > would be useful to me in experimenting/developing/debugging.) > > It looks like (I haven't tried it) $_SERVER['QUERY_STRING'] would give > me the entire URL but I'd really rather not have to parse it. > > Thanks, Bob (a very new noob) $_GET[] is an array Look at the manual on how to print a whole array.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2011-09-21 23:46 +0200 |
| Message-ID | <1888520.Oct5B3EuLq@PointedEars.de> |
| In reply to | #3188 |
eBob.com wrote:
^^^^^^^^
You really want to put a real name there. I usually don't talk to domains.
> I know that I can get and print the value of a URL parameter this way ...
>
> echo '<p>phone: ' . $_GET['phone'] . '</p>';
>
> ... and that works fine of course. But what if I don't know the names of
> all the parameters and just want to print out the names and values of all
> the parameters? (It might not seem to make a lot of sense, but it would
> be useful to me in experimenting/developing/debugging.)
>
> It looks like (I haven't tried it) $_SERVER['QUERY_STRING'] would give me
> the entire URL but I'd really rather not have to parse it.
Think about it: Why does $_GET['phone'] work in the first place?
> Thanks, Bob (a very new noob)
^^^^^^^^^^^^^
Don't.
<http://catb.org/~esr/faqs/smart-questions.html#id478703>
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
[toc] | [prev] | [next] | [standalone]
| From | "eBob.com" <eBob.com@totallybogus.com> |
|---|---|
| Date | 2011-09-21 23:27 -0400 |
| Message-ID | <yWxeq.183410$fD6.9051@en-nntp-02.dc1.easynews.com> |
| In reply to | #3190 |
Yes, of course. Thank you PointedEars and Natural Philosopher. Although I have done a lot of programming in many different languages, I am brand new to PHP, and this was my first experience of any kind with arrays. It just wasn't clicking that 'phone' (in my example) was a subscript. I don't think I've used a language before in which plain ol' arrays can have character string "subscripts". Thanks again for the help. Bob "Thomas 'PointedEars' Lahn" <PointedEars@web.de> wrote in message news:1888520.Oct5B3EuLq@PointedEars.de... > eBob.com wrote: > ^^^^^^^^ > You really want to put a real name there. I usually don't talk to > domains. > >> I know that I can get and print the value of a URL parameter this way ... >> >> echo '<p>phone: ' . $_GET['phone'] . '</p>'; >> >> ... and that works fine of course. But what if I don't know the names of >> all the parameters and just want to print out the names and values of all >> the parameters? (It might not seem to make a lot of sense, but it would >> be useful to me in experimenting/developing/debugging.) >> >> It looks like (I haven't tried it) $_SERVER['QUERY_STRING'] would give me >> the entire URL but I'd really rather not have to parse it. > > Think about it: Why does $_GET['phone'] work in the first place? > >> Thanks, Bob (a very new noob) > ^^^^^^^^^^^^^ > Don't. > > <http://catb.org/~esr/faqs/smart-questions.html#id478703> > > > PointedEars > -- > Use any version of Microsoft Frontpage to create your site. > (This won't prevent people from viewing your source, but no one > will want to steal it.) > -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
[toc] | [prev] | [next] | [standalone]
| From | "Peter H. Coffin" <hellsop@ninehells.com> |
|---|---|
| Date | 2011-09-22 07:43 -0500 |
| Message-ID | <slrnj7mbb7.bek.hellsop@nibelheim.ninehells.com> |
| In reply to | #3191 |
On Wed, 21 Sep 2011 23:27:18 -0400, eBob.com wrote:
> Yes, of course. Thank you PointedEars and Natural Philosopher.
> Although I have done a lot of programming in many different languages,
> I am brand new to PHP, and this was my first experience of any kind
> with arrays. It just wasn't clicking that 'phone' (in my example) was
> a subscript. I don't think I've used a language before in which plain
> ol' arrays can have character string "subscripts".
Other languages probably just called them "hashes" instead. The
difference is largely semantics, in either direction.
--
Every fleeting thought you've ever had in your life, no matter how
bizarre, is someone's lifelong obsession. And he has a website.
-- Skif's Internet Theorem
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <news.x.richarddamon@xoxy.net> |
|---|---|
| Date | 2011-09-22 13:36 -0400 |
| Message-ID | <j5frm4$mt0$1@dont-email.me> |
| In reply to | #3191 |
On 9/21/11 11:27 PM, eBob.com wrote: > Yes, of course. Thank you PointedEars and Natural Philosopher. Although > I have done a lot of programming in many different languages, I am brand > new to PHP, and this was my first experience of any kind with arrays. It > just wasn't clicking that 'phone' (in my example) was a subscript. I > don't think I've used a language before in which plain ol' arrays can > have character string "subscripts". > > Thanks again for the help. > > Bob > > Actually, those aren't "plain ol' arrays" but associative arrays, which just happen to use the same syntax as the simple linear array.
[toc] | [prev] | [next] | [standalone]
| From | tamouse <tamouse.lists@gmail.com> |
|---|---|
| Date | 2011-09-28 11:46 -0700 |
| Message-ID | <21105381.202.1317235599809.JavaMail.geo-discussion-forums@vbkm14> |
| In reply to | #3188 |
Since the question seems directed to debugging, you should know about two functions: print_r and var_dump:
http://us2.php.net/manual/en/function.print-r.php
http://us2.php.net/manual/en/function.var-dump.php
In both of these cases, the standard behaviour is to dump the variable structure straight to the standard output (most likely your browser window/tab). This can be problematic for a few reasons, and can be a security risk if you're not careful.
print_r has a second paramter, which if set to TRUE, will return it's output as a string, which you can sanitize before sending to output thus:
echo "<pre>" . htmlentities(print_r($var,TRUE)) . "</pre>" . PHP_EOL;
This sort of thing will prove invaluable in debugging php code for the newbie.
If you're doing a fair bit of this, you might want to set up a function for debugging, and use a global to turn on/off debugging. Lots of these exist already, some very sophisticated, some very simple.
Extremely simple:
function dbg($var)
{
if ($GLOBALS['DEBUG'])
{
echo "<pre>".print_r($var,TRUE)."</pre>".PHP_EOL;
}
}
And you can set $GLOBALS['DEBUG'] in a number of ways, such as in a common configuration file that is included in your application, or by introducing a DEBUG parameter in the $_REQUEST hash.
Some people (*cough*) go so far as to write a debugger class with all sorts of fancy bells and whistles, such as including the file, function, and line number where the debugging call is made, among others.
[toc] | [prev] | [next] | [standalone]
| From | tamouse <tamouse.lists@gmail.com> |
|---|---|
| Date | 2011-09-28 12:18 -0700 |
| Message-ID | <8149928.293.1317237523058.JavaMail.geo-discussion-forums@vbac9> |
| In reply to | #3226 |
On Wednesday, September 28, 2011 1:46:39 PM UTC-5, tamouse wrote:
> function dbg($var)
> {
> if ($GLOBALS['DEBUG'])
> {
> echo "<pre> ".print_r($var,TRUE)."</pre>".PHP_EOL;
> }
> }
Woops. that echo line should read:
echo "<pre> ".htmlentities(print_r($var,TRUE))."</pre>".PHP_EOL;
[toc] | [prev] | [next] | [standalone]
| From | sheldonlg <sheldonlg@thevillages.net> |
|---|---|
| Date | 2011-09-29 09:15 -0400 |
| Message-ID | <j61rlr$fae$1@dont-email.me> |
| In reply to | #3226 |
On 9/28/2011 2:46 PM, tamouse wrote:
> Since the question seems directed to debugging, you should know about two functions: print_r and var_dump:
>
> http://us2.php.net/manual/en/function.print-r.php
> http://us2.php.net/manual/en/function.var-dump.php
>
> In both of these cases, the standard behaviour is to dump the variable structure straight to the standard output (most likely your browser window/tab). This can be problematic for a few reasons, and can be a security risk if you're not careful.
>
> print_r has a second paramter, which if set to TRUE, will return it's output as a string, which you can sanitize before sending to output thus:
>
> echo "<pre>" . htmlentities(print_r($var,TRUE)) ."</pre>" . PHP_EOL;
>
> This sort of thing will prove invaluable in debugging php code for the newbie.
>
> If you're doing a fair bit of this, you might want to set up a function for debugging, and use a global to turn on/off debugging. Lots of these exist already, some very sophisticated, some very simple.
>
> Extremely simple:
>
> function dbg($var)
> {
> if ($GLOBALS['DEBUG'])
> {
> echo "<pre>".print_r($var,TRUE)."</pre>".PHP_EOL;
> }
> }
>
> And you can set $GLOBALS['DEBUG'] in a number of ways, such as in a common configuration file that is included in your application, or by introducing a DEBUG parameter in the $_REQUEST hash.
>
> Some people (*cough*) go so far as to write a debugger class with all sorts of fancy bells and whistles, such as including the file, function, and line number where the debugging call is made, among others.
I would use $_SESSION['DEBUG'] instead.
--
Shelly
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web