My EOT font doesn't work in PHP. It only work in HTML. Can anyone help me? Thanks.

Dani AI

Generated

Short answer: PHP itself doesn't change how a webfont is applied — fonts are controlled by CSS. The usual reason an EOT "works in HTML but not PHP" is a deployment/path/header problem, not PHP echo/print. 's point about how the text is emitted was right: printing text from PHP still relies on CSS for fonts, so check how the CSS and font file URLs are being served when the page is produced by PHP. 's later "it was fine" typically means one of the items below was fixed.

Quick troubleshooting checklist:

  • Use the browser DevTools Network tab and request the .eot directly. Note the HTTP status and response headers.
  • Verify the font URL is correct. For an external CSS file, font URLs are resolved relative to the CSS file URL; for inline CSS in a PHP-generated page, they resolve relative to the page URL.
  • Ensure the server sends the correct MIME type (application/vnd.ms-fontobject) or add it via server config/.htaccess.
  • If a PHP script serves the font, send binary-safe output with correct headers and no extra whitespace or BOM.
  • Watch for rewrite rules that route asset requests to index.php and for cross-origin blocking (set Access-Control-Allow-Origin if fonts are on another origin).
  • Avoid mixed-content: serve fonts over HTTPS on HTTPS pages.

Example @font-face (EOT fallback plus modern formats):

@font-face {
  font-family: 'MyFont';
  src: url('/fonts/MyFont.eot');
  src: url('/fonts/MyFont.eot?#iefix') format('embedded-opentype'),
       url('/fonts/MyFont.woff2') format('woff2'),
       url('/fonts/MyFont.woff') format('woff'),
       url('/fonts/MyFont.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

If a PHP file must serve the .eot, use a binary-safe script and the proper headers:

<?php
$file = __DIR__ . '/fonts/MyFont.eot';
if (!is_file($file)) { header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); exit; }
header('Content-Type: application/vnd.ms-fontobject');
header('Content-Length: '.filesize($file));
header('Cache-Control: public, max-age=31536000');
readfile($file);
exit;

Note: EOT is mainly needed only for very old Internet Explorer versions; for modern sites, prefer WOFF/WOFF2 and include EOT only as a legacy fallback.

Recommended Answers

All 4 Replies

What does EOT mean?

EOT means Embedded OPen Type Font. a compact form of OpenType fonts designed by Microsoft for use as embedded fonts on web pages. These files usually use the extension ".eot".
Go there and this will explain completely.
http://en.wikipedia.org/wiki/Embedded_OpenType

Ok, so are you saying that your font doesn't work when you try to display text with PHP via an echo or print? How are you setting the font without using HTML or CSS?

It was fine. Thanks for your reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.