我有一些大的HEX值,我想显示为常规数字,我使用hexdec()转换为float,我在PHP.net上找到一个函数将其转换为十进制,但它似乎达到了上限,例如:
$h = 'D5CE3E462533364B';
$f = hexdec($h);
echo $f .' = '. Exp_to_dec($f);
Run Code Online (Sandbox Code Playgroud)
输出:1.5406319846274E + 19 = 15406319846274000000
来自calc.exe = 15406319846273791563的结果
还有另一种转换大十六进制值的方法吗?
我在我的本地计算机上使用PHP 5.3中的DateTime对象进行了一些有用的操作但是我的主机(NFS)只运行了5.2并且在5.3.1之前不打算升级.
所以我的问题是,这个代码是否可以使用5.2?具体来说,5.2中不存在DateTime :: getTimestamp
nicetime.php包含类似于http://cz2.php.net/manual/en/function.time.php#89415中的那个,基本上只输出时间戳之前/之前的时间长度)
include('include/nicetime.php');
if(isset($_GET['hour']) && isset($_GET['min']) && isset($_GET['AP']) && isset($_GET['TZ'])){
if($_GET['AP'] == 'PM'){
$reqHour = $_GET['hour']+12;
}else{
$reqHour = $_GET['hour'];
}
$reqHour = ($_GET['AP'] == 'PM' ? $_GET['hour']+12 : $_GET['hour']);
$reqMin = ($_GET['min'] == 0 ? '00': $_GET['min']);
date_default_timezone_set($_GET['TZ']);
$reqDate = date_create($reqHour.':'.$reqMin);
echo '<h3>'.nicetime($reqDate->getTimestamp()).'</h3>';
}
?>
Run Code Online (Sandbox Code Playgroud)
如果您想知道它的重点是什么,用户想要知道在一个时区中某个时间段与他们不同的时间.例如,什么时候在英格兰的晚上9点?从现在起2个小时.
I was surprised to see that the following doesn't work as expected.
define('CONST_TEST','Some string');
echo "What is the value of {CONST_TEST} going to be?";
Run Code Online (Sandbox Code Playgroud)
outputs: What is the value of {CONST_TEST} going to be?
Is there a way to resolve constants within curly braces?
Yes, I am aware I could just do
echo "What is the value of ".CONST_TEST." going to be?";
Run Code Online (Sandbox Code Playgroud)
but I'd prefer not to concatanate strings, not so much for performance but for readability.
下面是我正在尝试的代码(加上一些变体),有一个对话框要求我的许可,但仍然出错
错误:获取属性 XPCComponents.classes 的权限被拒绝
unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var file = unsafeWindow.Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("d:\\test.bat");
var process = unsafeWindow.Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(file);
var args = ["argument1", "argument2"];
process.run(false, args, args.length);
Run Code Online (Sandbox Code Playgroud)
这是不可能的吗?
我得到的图像文件在文件名中有捷克语字符(例如,ěščřžýáíé),我想重新命名它们而不需要重音符号,这样它们就更适合网络.我以为我可以使用一个简单的str_replace函数,但它似乎与文件数组的工作方式不同,它与字符串文字一样.
检查扩展后,我用readdir读取文件.
function readFiles($dir, $ext = false) {
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($ext){
if(end(explode('.', $file)) == $ext) {
$f[] = $file;
}
} else {
$f[] = $file;
}
}
closedir($dh);
return $f;
} else {
return false;
}
} else {
return false;
}
}
$files = readFiles(".", "jpg");
$search = array('š','á','ž','í','?','é','?','?','ý','?',' ');
$replace = array('s','a','z','i','e','e','r','n','y','c','-');
$string = "?š?áýísdjksnalci sáš?ééalskcnkkjy+?éší";
$safe_string = str_replace($search, $replace, $string);
echo '<pre>';
foreach($files …Run Code Online (Sandbox Code Playgroud) 如果不满足某些条件,我想将php脚本输出像真正的404页面(在Apache ErrorDocument指令中设置).我不知道我怎么能/如果可以从PHP访问这个值..
if(!@$_SESSION['value']){
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
echo $default_page['404'];
exit();
}
echo 'Welcome to a secret place.';
Run Code Online (Sandbox Code Playgroud)
我理解ErrorDocument值可以被覆盖,但我对Apache硬编码的'default'值特别感兴趣.如果可以知道被覆盖的值(例如通过.htaccess文件),那么这是一个奖励:)
http://httpd.apache.org/docs/2.0/mod/core.html#ErrorDocument
编辑:要清楚,我想从PHP发送内容默认的404页面(或403等).如果我只使用header它自己,则没有任何内容输出到客户端/用户(至少在FF/Chrome中,IE有自己的内置页面显示).
是否可以ArrayList在扩展的类中使用Thread?我已经写了一些代码来从蓝牙序列中读取它正在工作,但我添加了一个ArrayList跟踪我正在阅读的内容.但是,我正在NullPointException访问任何访问结果的行.我知道这ArrayList不是线程安全的(虽然我可能不完全理解这意味着什么)所以我可能会尝试做不可能的事情,但我想我会与专家核实,因为ArrayLists非常容易使用.
private class ConnectedThread extends Thread {
private final BluetoothSocket mmSocket;
private final InputStream mmInStream;
private List<String> results;
public ConnectedThread(BluetoothSocket socket) {
Log.d(TAG, "create ConnectedThread");
mmSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;
List<String> results = new ArrayList<String>();
// Get the BluetoothSocket input and output streams
try {
tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
} catch (IOException e) {
Log.e(TAG, "temp sockets not created", e); …Run Code Online (Sandbox Code Playgroud) php ×5
android ×1
apache ×1
arraylist ×1
const ×1
curly-braces ×1
datetime ×1
greasemonkey ×1
hex ×1
java ×1
javascript ×1
local-files ×1
php-5.2 ×1
readdir ×1
str-replace ×1