Example (var site):
Code: Select all
www.mysite.com/index.php?site=29&web=page123&site=A29394232&name=Bob&site=002How do I discern between the three variables all named the same thing?
Thanks!
-- Abe --
Moderator: General Moderators
Code: Select all
www.mysite.com/index.php?site=29&web=page123&site=A29394232&name=Bob&site=002How do I get the URL? I triedPrObLeM wrote:since you can't use the $_GET['site'] because it just return the last var you can try parse_url() to get the query string, then parse it from there.
Code: Select all
<?php echo parse_url(); ?>Warning: parse_url() expects exactly 1 parameter, 0 given in /home/laurels/public_html/abe/client/index3.php on line 128
Code: Select all
$array = parse_url( $urlString );Code: Select all
$arr = array();
foreach(explode('&', $_SERVER['QUERY_STRING']) as $chunk) {
$arr[] = explode('=', $chunk);
}
var_dump($arr);PrObLeM, your reply wasn't particularly useful, did you mean parse_str()?PrObLeM wrote:You need to read the manual....Code: Select all
$array = parse_url( $urlString );
No i ment parse_urlWeirdan wrote:PrObLeM, your reply wasn't particularly useful, did you mean parse_str()?PrObLeM wrote:You need to read the manual....Code: Select all
$array = parse_url( $urlString );
Then you need to parse $array['query']parse_url -- Parse a URL and return its components
This function parses a URL and returns an associative array containing any of the various components of the URL that are present.
I never said that it was the only way, plus you are assuming that you can use the $_SERVER vars, the url maybe hardcoded in or passed from somewhere else (ie xml file, flatfile, etc).Weirdan wrote:<sarcasm on>PrObLeM wrote: [....]
Then you need to parse $array['query']
instead of parsing $_SERVER['QUERY_STRING'] directly...
</sarcasm off>
Code: Select all
function getQueryStringParameters() {
$params = array();
if ($_SERVER['QUERY_STRING']) {
$pairs = explode('&', $_SERVER['QUERY_STRING']);
$i = 0;
foreach($pairs as $pair) {
list($params[$i]['name'], $params[$i]['value']) = explode('=', $pair);
++$i;
}
}
return $params;
}
echo '<pre>' . print_r(getQueryStringParameters(), 1) . '</pre>';Code: Select all
$triggerchar = "Z";
$triggervarname = "first";My company is using a portal application for email, etc and it's real buggy when working with things in the outside world and incorporating them into the environment. I don't have the access level to control the output I'm provided with, so I need to work with what I have.arborint wrote:Perhaps you should deal with that problem first. What kind of "wierd output I can't control"?BigAbe wrote:The reason I have to take this approach is that I'm recieving wierd output I can't control, and the exact info I want is embedded in there somewhere.
Code: Select all
// for: ?first=Zip&first=Zero&first=Xap
array(
0 => array (
'name' => 'first',
'value' => 'Zip',
),
1 => array (
'name' => 'first',
'value' => 'Zero',
),
2 => array (
'name' => 'first',
'value' => 'Xap',
),
);Code: Select all
$triggerchar = "Z";
$triggervarname = "first";
$params = getQueryStringParameters();
foreach ($params as $param) {
if (($param['name'] == $triggervarname) && (strpos($param['value'], $triggerchar) !== false)) {
echo "found: {$param['name']}={$param['value']}";
}
}