<?php

// Task 06: Write a PHP script InformationTable.php which generates an HTML table
//          by given information about a person (name, phone number, age, address).
//          Styling the table is optional. Semantic HTML is required.
function GenerateTable($name, $phone, $age, $address)
{
    $result = "<tr><td>Name</td><td>{$name}</td></tr>";
    $result .= "<tr><td>Phone number</td><td>{$phone}</td></tr>";
    $result .= "<tr><td>Age</td><td>{$age}</td></tr>";
    $result .= "<tr><td>Address</td><td>{$address}</td></tr>";
    return "<table><tbody>{$result}</tbody></table>";
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>HTML Table</title>
    <link rel="stylesheet" href="styles/style.css"/>
</head>
<body>
<section>
    <?php 
echo GenerateTable("Goshko", "0882-321-423", 24, "Hadji Dimitar");
?>
    <?php 
echo GenerateTable("Pesho", "0884-888-888", 67, "Suhata Reka");
?>
</section>
</body>
</html>
Example #2
0
function FormatDescription($description, $baseclass = "")
{
    $lines = explode("\r\n", $description);
    $inList = false;
    $inCode = false;
    $inTable = false;
    $tableEnd = false;
    $tableStart = false;
    $tableContent = array();
    $result = "";
    foreach ($lines as $line) {
        $line = ProcessLinks($line, $baseclass);
        $line = ProcessExtLinks($line);
        if (!(strpos(strtolower($line), "<code>") === false)) {
            $inCode = true;
        }
        if (!(strpos(strtolower($line), "<table>") === false)) {
            $inTable = true;
            $tableStart = true;
            $tableContent = "";
        }
        if (!(strpos(strtolower($line), "</table>") === false)) {
            $inTable = false;
            $tableEnd = true;
            $result .= "\n" . GenerateTable($tableContent) . "\n";
        }
        if (substr(ltrim($line), 0, 2) == "- ") {
            $line = substr($line, 3);
            if (!$inList) {
                $line = "<ul><li>" . $line . "</li>\n";
            } else {
                $line = "<li>" . $line . "</li>\n";
            }
            $inList = true;
        } else {
            if ($inList) {
                $line = "</ul>\n" . $line;
            }
            $inList = false;
            if ($inCode) {
                $line = EscapeHtmlMarkers($line) . "\n";
            } else {
                if (!$inTable) {
                    $line = $line . "<br>\n";
                }
            }
        }
        // Can't use str_ireplace, it's PHP5 only
        $line = preg_replace("/\\\\<CODE\\\\>/i", "<CODE><PRE>", $line, 1);
        $line = preg_replace("/\\\\<\\/CODE\\\\>/i", "</PRE></CODE>", $line, 1);
        if ($inTable && !$tableStart) {
            $tableContent[] = $line;
        } else {
            if (!$tableEnd && !$tableStart) {
                $result .= UnescapeHtmlMarkers($line);
            }
        }
        if (!(strpos(strtolower($line), "</code>") === false)) {
            $inCode = false;
        }
        $tableEnd = false;
        $tableStart = false;
    }
    return $result;
}