Forum Moderators: coopster

Message Too Old, No Replies

Newbie trying to explode

What's wrong with this explode page

         

calvinmicklefinger

3:33 am on Jan 17, 2005 (gmt 0)

10+ Year Member



I am trying to explode my REQUEST_URI to get two pieces of information, but I am seeing only one when I echo.

The Requested URI is /10015/myphpform
**********************

The code is
**********************
<body>
<?php
$uri_array = explode("/", $REQUEST_URI,3);
?><br>
<?php
echo 'The Number =' . $uri_array[0];
?><br>
<?php
echo 'The Page =' . $uri_array[1];
?><br>
<?php
echo 'What is this? =' . $uri_array[3];
?><br>
The file <?php echo $REQUEST_URI;?> was requested
**********************

The rendered web page shows
**********************
The Number =
The Page =10015
What is this? =
The file /10015/myphpform was requested
**********************

Why is my second part of the REQUEST_URI showing from the array?

How can I correct it?

Many thanks for anll help.

demnetia

5:35 am on Jan 17, 2005 (gmt 0)

10+ Year Member



What's happening is correct: the URI is exploded into three parts:

0. empty
1. number
2. page

You have the empty part because the URI started with /

Just use var_dump($uri_array) to debug faster.

RedScourge

5:35 am on Jan 17, 2005 (gmt 0)

10+ Year Member



youre problem is probably that you want 0, 1, and 2, not 0, 1, and 3.

"echo 'What is this? =' . $uri_array[3];"

becomes:

"echo 'What is this? =' . $uri_array[2];"

that help?

calvinmicklefinger

11:48 am on Jan 17, 2005 (gmt 0)

10+ Year Member



I guess I should say something like "Oh fiddle!" I hadn't noticed the typo on the third echo. It was supposed to have been a [2], not a [3]. Your comment pointed that out. Many Thanks.

This would be the first time I have ever used a PHP function. But I should know the numbering of array items.

Again, many thanks. This allows me to perform a task I was unable to do with the RewriteRule in .htaccess

CM