QRMarkupHTML.md.txt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # QRMarkupHTML
  2. [Class `QRMarkupHTML`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRMarkupHTML.php): HTML output
  3. This class is a cheap markup substitute for when SVG is not available or not an option (which was an issue before ca 2012).
  4. As a general rule: if you plan to display the QR Code in a web browser, you should be using the [SVG output](../Built-In-Output/QRMarkupSVG.md).
  5. ## Example
  6. See: [HTML example](https://github.com/chillerlan/php-qrcode/blob/main/examples/html.php)
  7. Set the options:
  8. ```php
  9. $options = new QROptions;
  10. $options->outputInterface = QRMarkupHTML::class;
  11. $options->cssClass = 'qrcode';
  12. $options->moduleValues = [
  13. // finder
  14. QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
  15. QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
  16. QRMatrix::M_FINDER => '#FFBFBF', // light (false)
  17. // alignment
  18. QRMatrix::M_ALIGNMENT_DARK => '#A70364',
  19. QRMatrix::M_ALIGNMENT => '#FFC9C9',
  20. ];
  21. ```
  22. Output in a HTML document (via PHP):
  23. ```php
  24. <?php
  25. $data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
  26. $out = (new QRCode($options))->render($data);
  27. header('Content-type: text/html');
  28. ?>
  29. <!DOCTYPE html>
  30. <html lang="none">
  31. <head>
  32. <meta charset="UTF-8"/>
  33. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  34. <title>QRCode HTML Example</title>
  35. <style>
  36. div.qrcode{
  37. margin: 1em;
  38. }
  39. /* rows */
  40. div.qrcode > div {
  41. height: 10px;
  42. }
  43. /* modules */
  44. div.qrcode > div > span {
  45. display: inline-block;
  46. width: 10px;
  47. height: 10px;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <!-- php poutput -->
  53. <?php echo $out; ?>
  54. </body>
  55. </html>
  56. ```
  57. ## Additional methods
  58. | method | return | description |
  59. |----------------------------------------------|----------|-------------------------------------------------------------------------|
  60. | (protected) `createMarkup(bool $saveToFile)` | `string` | Returns the fully parsed and rendered markup string for the given input |
  61. | (protected) `getCssClass(int $M_TYPE = 0)` | `string` | Returns a string with all css classes for the current element |
  62. ## Options that affect this class
  63. | property | type |
  64. |----------------|----------|
  65. | `$cssClass` | `string` |
  66. | `$eol` | `string` |