Forum Moderators: coopster
I am pretty sure I want to use strstr to get...
1.8
out of...
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5
and I just want to associate whatever value (in this case "1.8") to the $gecko variable.
I'm not sure how to say I want to...
1.) Remove up to and including "rv:"
2.) Remove ") Gecko" and on till the end of the string.
3.) Reference the remaining string to the $gecko variable.
The one thing I do have declared is...
$ua = getenv("HTTP_USER_AGENT");
John
I tried this but I didn't get any output (or errors)? My UA is the default (double-checked before I replied).
<?php
$ua = getenv("HTTP_USER_AGENT");
$gecko = "";
$rvpos = strpos($ua,'rv:');
if ($rvpos!== FALSE)
{
$rvend = strpos($ua,')',$rvpos);
if ($rvend!== FALSE)
{
$gecko = trim(substr($ua,$rvpos+3,$rvend-$rvpos-3));
}
}
?>
I'm really not qualified but...
I think $rvpos might be the issue?
Do we want to throw this in to two phases perhaps? First take the variable and remove the beginning, output what we have, then do the same to the end?
I understand each part of the script in incremental logic at least. :)
John
Here is what I'm testing just so we're on the same page. :)
<?php
$ua = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5";
echo $ua;
echo '<br />';
$gecko = "";
$rvpos = strpos($ua,'rv:');
if ($rvpos!== FALSE)
{
$rvend = strpos($ua,')',$rvpos);
if ($rvend!== FALSE)
{
$gecko = trim(substr($ua,$rvpos+3,$rvend-$rvpos-3));
}
}
?>
We didn't echo/print $gecko. *smacks forhead*
<?php$ua = $_SERVER['HTTP_USER_AGENT'];
echo $ua;
echo '<br />';
$gecko = "";
$rvpos = strpos($ua,'rv:');
if ($rvpos!== FALSE)
{
$rvend = strpos($ua,')',$rvpos);
if ($rvend!== FALSE)
{
$gecko = trim(substr($ua,$rvpos+3,$rvend-$rvpos-3));
}
}
echo $gecko;
?>
Kick ass! Thanks a ton Arjan! :)
John
<?php
$ua = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5";
$gecko = "";
$rvpos = strpos($ua,'rv:');
if ($rvpos!== FALSE)
{
$rvend = strpos($ua,')',$rvpos);
if ($rvend!== FALSE)
{
$gecko = trim(substr($ua,$rvpos+3,$rvend-$rvpos-3));
}
}
echo "ua='$ua'\n";
echo "gecko='$gecko'\n";
echo "rvpos='$rvpos'\n";
echo "rvend='$rvend'\n";
?>
When running this I get the following output:
X-Powered-By: PHP/4.4.2
Content-type: text/html
ua='Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5'
gecko='1.8'
rvpos='48'
rvend='54'
I have no idea what is wrong with your setup
[edit adb64]Oops, just saw your last post when I submitted mine. Great it works now :-)[/edit]