【发布时间】:2016-01-26 09:13:32
【问题描述】:
我有当前代码,它只有在我注释掉函数时才有效。帮助? 它不显示标题标签或任何东西。我在想这是我缺少的一些语法,但还没有看到它。
<html>
<head>
<title>Convert to Roman</title>
</head>
<body>
<?php
function integerToRoman($integer)
{
// Convert the integer into an integer (just to make sure)
$integer = intval($integer);
$result = '';
// Create a lookup array that contains all of the Roman numerals.
$lookup = array('M' => 1000,
'CM' => 900,
'D' => 500,
'CD' => 400,
'C' => 100,
'XC' => 90,
'L' => 50,
'XL' => 40,
'X' => 10,
'IX' => 9,
'V' => 5,
'IV' => 4,
'I' => 1);
foreach($lookup as $roman => $value){
// Determine the number of matches
$matches = intval($integer/$value);
// Add the same number of characters to the string
$result .= str_repeat($roman,$matches);
// Set the integer to be the remainder of the integer and the value
$integer = $integer % $value;
}
// The Roman numeral should be built, return it
return $result;
}
echo integerToRoman(5);
?>
</body>
</html>
【问题讨论】:
-
error_reporting(E_ALL);
-
试过了。那只是在
-
它工作正常...在这里查看演示sandbox.onlinephpfunctions.com/code/…
-
你的文件扩展名是什么??
-
由于某种原因它不会出现在我的浏览器中。有什么提示吗?我运行了 LAMP 并检查了所有 php 先决条件。
标签: php