Mayeenul Islam
Mayeenul Islam

Reputation: 4762

Is it possible to check browser's default font setup using PHP?

As per my Question regarding Unicode Character-specific CSS, I got a good solution: unicode-range, but in reality it's not actually working, or it's working without any visible changes.

And I followed the Bulletproof @font-face Syntax Tutorial by Paul Irish for indexing my embeddable fonts. It's somehow embedding fonts, but not correctly (My problem is specific to Bānglā fonts). If I set up the font in my browser, then it's giving the perfect size and glyph view of the font. But if I delete the specific font from /windows/fonts folder, then the embed is NOT showing the texts in correct sizes. So the actual font-size property is my problem.

If I can detect whether the Bānglā font is default in the browser then I'll load smaller fonts, if not then I'll load a bigger.

So, is it really possible to detect which is the Default Font enabled in a browser?

EDIT

My live site is dev.nanodesignsbd.com - if that could help somebody to find a bug in @font-face bulletproof syntax. And the attached image will talk for me: what I want my fonts

And that can only be done with a browser font setup. :(

Upvotes: 0

Views: 971

Answers (3)

Matthew R.
Matthew R.

Reputation: 4350

Typically the default font is placed on the <body> or <html> tags with CSS. These are defined by default in the browsers configuration. The only was to get the default for a specified browser in PHP would be to see what the defaults are for each browser and each language you want to support. You would then have to parse the user agent string to see which default should be in place.

The best solution would not be in PHP since, as I said, the browsers define these fonts in CSS. Rather, you can use javascript to check what the default font is after the page has loaded.

You can do this with getComputedStyle() like so:

FOR HTML TAG

window.getComputedStyle(document.body.parentNode);

FOR BODY TAG

window.getComputedStyle(document.body);

These will return an array of the computed styles for the browser.

Hope this helps!

Upvotes: 1

Boundless
Boundless

Reputation: 2464

PHP will let you get some information about the browser. None of the information is regarding font.

http://php.net/manual/en/function.get-browser.php

I think this is the most platform specific information you'll get:

$browser = get_browser(null, true);
print_r($browser);

Array
(
    [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
    [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
    [parent] => Firefox 0.9
    [platform] => WinXP
    [browser] => Firefox
    [version] => 0.9
    [majorver] => 0
    [minorver] => 9
    [cssversion] => 2
    [frames] => 1
    [iframes] => 1
    [tables] => 1
    [cookies] => 1
    [backgroundsounds] =>
    [vbscript] =>
    [javascript] => 1
    [javaapplets] => 1
    [activexcontrols] =>
    [cdf] =>
    [aol] =>
    [beta] => 1
    [win16] =>
    [crawler] =>
    [stripper] =>
    [wap] =>
    [netclr] =>
)

Upvotes: 0

Amal Murali
Amal Murali

Reputation: 76646

PHP is a server-side language and runs on the web server. It has no control over the user's web browser and can't really determine the font (or anything else, for that matter). For dealing with client-side stuff, you'll need JavaScript. That said, I don't think it's possible to reliably determine the font using JavaScript, either.

Upvotes: 3

Related Questions