Yeah, you probably should escape the "." with a "\", just in case your script is still being used when MSIE 600.0 comes out.
[RESOLVED] preg_match, searching with a space
ummm. i guess it is something to do with server setups? if i run it locally it seems to work, however if i upload it to a server it does not seem to work; and as you would think the server is a little more important :p
To cut a long story short i want to be able to choose if the browser supports transparently on .png images, if so it will display .png images, if not other images.
You could always include the transparent-PNG Javascript solution if the user is running IE using HTML conditionals, e.g.
<!--[if IE]>
<script type="text/javascript" src="/scripts/png_fix.js"></script>
<![endif]-->
thanks, but i kind of need to find the solution using php
Well, you're always kind of in a pickle if you need to depend on the user_agent string, as it's not required that the browser send it, there's no standard content protocol to which it must adhere, nothing prevents the browser from sending whatever string it (or the user) wants it to send, and even if it sends the sort of string you're expecting, it may be modified or deleted by any firewall and/or proxy the request goes through.
Anyway, I just noticed in your first post that you mentioned trying "/s". Maybe that was just a typo, but it should use a back-slash: "\s".
While I'd probably try to find a client-side solution using IE conditional comments in order to put the reponsibility on IE to deal with its short-comings, I might try something like this for your regexp:
'/MS\s*IE\s*6\.0/i'
ah yes sorry that was a typo it was meant to be \s
'/MS\s*IE\s*6\.0/i'
I tried the above and it also didn't work on the server but worked locally.
Obviously this is really not the way to do it, I was going to use variables to set the image extension (either .png or .gif) depending on browser.
What could I use to do this (php ways ), bearing in mind that IE7 can support transparent png images and IE6 can't (thats the only thing that IE 7 does right , not that well either)
Start by trying the following to see exactly what $SERVER variables are actually being set on your host, and what values they have:
<?php
echo "<pre>".print_r($_SERVER, 1)."</pre>";
PS: You are accessing the $_SERVER['HTTP_USER_AGENT'] variable and not something deprecated like the $HTTP_SERVER_VARS array or, even worse, the register_globals variable $HTTP_USER_AGENT?
NogDog;10878657 wrote:PS: accessing the $_SERVER['HTTP_USER_AGENT'] variable and not something deprecated like the $HTTP_SERVER_VARS array or, even worse, the register_globals variable $HTTP_USER_AGENT?
I am using
getenv("http_user_agent");
I have just tried it using $_server and that didn't even work locally
I have just used the php code you have given me and it does give me the standard string for HTTP_USER_AGENT
It's case-sensitive, so make sure you use $SERVER['HTTP_USER_AGENT']. The environment variables are generally less dependable, thus I'd suggest getting it from the $SERVER array instead of getenv() (though neither is absolutely guaranteed to be set on a given host). You could try to cover all bets with something like:
if(isset($_SERVER['HTTP_USER_AGENT']))
{
$browser = $_SERVER['HTTP_USER_AGENT'];
}
else
{
$browser = getenv('http_user_agent');
}
i see what you are saying, however neither of those seem to work for me, I'm stumped.
bump
basically i need to change the image links depending on what browser version there using :p
Well, you need to find out where on your server that information is provided. If it's not in the $SERVER array and not in the $ENV array, then I have no idea where to look. As I suggested in post #10, try a print_r() of each ($SERVER and then $ENV) and see what array element, if any, provides the browser info. If you find it, then use it to grab the desired info. If it's not there, then you're probably out of luck unless someone knows some place else that servers might hide that information.
NogDog;10878897 wrote:Well, you need to find out where on your server that information is provided. If it's not in the $SERVER array and not in the $ENV array, then I have no idea where to look. As I suggested in post #10, try a print_r() of each ($SERVER and then $ENV) and see what array element, if any, provides the browser info. If you find it, then use it to grab the desired info. If it's not there, then you're probably out of luck unless someone knows some place else that servers might hide that information.
I've already run that, and the information IS in $SERVER AND $ENV under HTTP_USER_AGENT
OK, you were confusing me then. (Not all that difficult to do.) It's not clear to me what the problem is. Can you call the following PHP script from an IE6 browser and show us the result?
<?php
echo "<pre>";
var_dump($_SERVER['HTTP_USER_AGENT']);
echo "</pre>";
Then at least we can see exactly what is being seen by PHP. (It would be best to copy-and-paste the output here within [noparse]
...
[/noparse] tags so we can see the exact amount of white space, newlines, etc.)
cool, sure here is the output
string(75) "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"
OK, so if I use that string, this regexp works fine for me:
// force value for testing:
$_SERVER['HTTP_USER_AGENT'] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
// test for IE 6.x via regexp:
if(preg_match('/MS\s*IE\s*6\.\d/i', $_SERVER['HTTP_USER_AGENT']))
{
echo "This is MSIE 6.0";
}
else
{
echo "This is something else";
}
At this point though, I'm not even sure if the regexp is the issue, or if it's something else you need. :eek:
Another option would be this, although it may not work on all servers:
$browser = get_browser(NULL, TRUE);
if($browser['browser'] == 'IE')
if($browser['majorver'] < 7) {
// browser is IE, version <7
} else {
// version >= 7
}
bradgrafelman;10878935 wrote:
$browser = get_browser(NULL, TRUE); if($browser['browser'] == 'IE') if($browser['majorver'] < 7) { // browser is IE, version <7 } else { // version >= 7 }
this one gives me "Warning: get_browser(): browscap ini directive not set"
NogDog;10878931 wrote:
// force value for testing: $_SERVER['HTTP_USER_AGENT'] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"; // test for IE 6.x via regexp: if(preg_match('/MS\s*IE\s*6\.\d/i', $_SERVER['HTTP_USER_AGENT'])) { echo "This is MSIE 6.0"; } else { echo "This is something else"; }
and this one gives me "This is MSIE 6.0" no matter what browser i am using
daveclose;10879011 wrote:...and this one gives me "This is MSIE 6.0" no matter what browser i am using
Did you comment out or delete the line where I explicitly set the string for testing purposes?
haha, no :o and thanks it now works