String variable array from url to meta tag SOLVED
Moderator: General Moderators
-
peaforabrain
- Forum Newbie
- Posts: 7
- Joined: Mon May 01, 2006 4:49 am
String variable array from url to meta tag SOLVED
Hi,
I am stuck on an array issue.
The problem is, a variable that is passed from the url into the html document, will only appear as the word ARRAY. I know that this has to be converted using an array command, but as yet, I cannot find the correct command to process it.
this is the sort of url
http://www.*********.php?style[]=whatever
All that appears on the page is 'array'.
Could anyone throw a suggestion my way?
Thanks
I am stuck on an array issue.
The problem is, a variable that is passed from the url into the html document, will only appear as the word ARRAY. I know that this has to be converted using an array command, but as yet, I cannot find the correct command to process it.
this is the sort of url
http://www.*********.php?style[]=whatever
All that appears on the page is 'array'.
Could anyone throw a suggestion my way?
Thanks
Last edited by peaforabrain on Mon Oct 09, 2006 9:20 am, edited 1 time in total.
-
peaforabrain
- Forum Newbie
- Posts: 7
- Joined: Mon May 01, 2006 4:49 am
Thanks for the interest.
The url can be generated from this search page;
http://www.beachwear.net/advanced_search.php?
and with a search generated from the options, it can be seen that the string variables are passed to the meta tags, some pass easily, but the style string doesn't.
Thanks
The url can be generated from this search page;
http://www.beachwear.net/advanced_search.php?
and with a search generated from the options, it can be seen that the string variables are passed to the meta tags, some pass easily, but the style string doesn't.
Thanks
sorry, a) I don't see where and how and b) I meant the php code anyway.
try
maybe also of interest: http://de2.php.net/serialze
try
Code: Select all
<?php
$arr = array(1,2,3);
echo '?' . $arr . "<br />\n"; // ?Array
// because the array was used in a string context
echo '?' . join(',', $arr) . "<br />\n"; // array elements concatenated
foreach($arr as $e) {
echo 'param[]=', $e, '&';
}
?>-
peaforabrain
- Forum Newbie
- Posts: 7
- Joined: Mon May 01, 2006 4:49 am
You will need to form your links differently. You could form the link by using a unique separator and exploding on it to get an array.
IE: http://www.somesite.com/page.php?param= ... -e-f-g-h-i
IE: http://www.somesite.com/page.php?param= ... -e-f-g-h-i
Code: Select all
$array = explode('-', $_GET['param']);
echo '<pre>';
print_r($array);
echo '</pre>';
//ouput
/*
Array
(
0 => a
1 => b
2 => c
3 => d
4 => e
5 => f
6 => g
7 => h
8 => i
)Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
try assign index to the param
or use vardump to know exactly what happen to that variable
Code: Select all
echo '$param[0] = '.$param[0];Not with my code.peaforabrain wrote:Thanks for the suggestion, but that didn't work, it outputs
param[]=Array
If you have used the
Code: Select all
foreach($arr as $e) {
echo 'param[]=', $e, '&';
}But can't tell you for sure, I gave my crystal ball away for cleaning
-
peaforabrain
- Forum Newbie
- Posts: 7
- Joined: Mon May 01, 2006 4:49 am
If you're using php5 http://de2.php.net/manual/en/function.h ... -query.php might help you.
Code: Select all
$arr = array(
'abc'=>array('a','b','c'),
'xyz'=>array('x','y','z')
);
echo http_build_query($arr);Ok, if I'm reading your initial post correctly, I think people are missing the problem here. It's not how to form the URLs, but how to access the values from form values that are arrays.
You have a page with a load of checkboxes with name="style[]". This is correct.
In the script listing_browse.php that receives the form submission you will have access to the following variable: $_GET['style']. This will be a single dimension array with numeric keys.
You haven't posted any code so I'm taking a guess here that you're doing something like:
This will output "Array", because that's exactly what it is, an array. To access single elements in the array you need to do something like:
to confirm this, as was suggested, try:
or
These will show you the structure of your variable.
You have a page with a load of checkboxes with name="style[]". This is correct.
In the script listing_browse.php that receives the form submission you will have access to the following variable: $_GET['style']. This will be a single dimension array with numeric keys.
You haven't posted any code so I'm taking a guess here that you're doing something like:
Code: Select all
echo $_GET['style'];Code: Select all
echo $_GET['style'][0];Code: Select all
var_dump($_GET['style']);Code: Select all
print_r($_GET['style']);-
peaforabrain
- Forum Newbie
- Posts: 7
- Joined: Mon May 01, 2006 4:49 am
print_r and var_dump are just functions that can be used when debugging to quickly and easily see what the structure and the values of your variables are.
An array is a data structure that holds multiple values in a single variable. There is no set output style for this so your question has many answers, depending on how you want to output the data.
Let's say you want to output each of the styles seperated by a comma, you could do that simply with the following as was suggested by volka:
Probably what you want to do is go over the array one element at a time using a loop and then you can customise the output how ever you want:
An array is a data structure that holds multiple values in a single variable. There is no set output style for this so your question has many answers, depending on how you want to output the data.
Let's say you want to output each of the styles seperated by a comma, you could do that simply with the following as was suggested by volka:
Code: Select all
echo join(', ', $_GET['style']);Code: Select all
foreach ($_GET['style'] as $key => $value)
{
echo $key.': '.$value.'<br/>';
}-
peaforabrain
- Forum Newbie
- Posts: 7
- Joined: Mon May 01, 2006 4:49 am
Solved
Thanks Chopsta, you are a great guy 