我花了几天时间研究互联网,但我找不到我理解并能够实现的答案.
我有一个网站,我想在其中使用include_once文件,并能够在localhost和实际服务器中正确查看网站.
我之前使用$_SERVER['DOCUMENT_ROOT']但它在localhost上不起作用,因此我很难更新并对网站进行更改.
我想要做的是创建一些config.php文件,在其中我可以告诉它根文件夹被调用htdocs或public_html"开始"从那里寻找文件.
或者还有其他任何方式我可以获得包含工作路径吗?
我已经看到了回复,例如dirname(__FILE__),__DIR__等等,但是他们从未解释过它是如何工作的,在代码中将它写在哪里等等.我有点厌倦了找到答案的一部分,然后在圈子里乱跑试着"填补"差距.我不是PHP专家,只是想通过使用它来让我的生活更轻松.
在大多数地方,权限被定义为格式为的八进制数0777.但UNIX的umask命令(因此os.umask())需要在我的理解中0o000产生权限位0o777和0o022等于0o755.
我听说UNIX umask由于某种原因而被颠倒了,我不明白其背后的原因.有人可以解释这个不一致吗?
我目前正在尝试为我的CSS文件实现压缩方法.我基本上复制的方式与我的JS文件相同,但它不起作用.我查看了Firebug工具,但没有加载CSS.
如何调用css.php哪个将调用压缩的CSS文件?
使用JS工作代码,文件是scripts.php(我没有指定.js扩展名):
<script type="text/javascript" src="js/scripts.php?build=123&load=foo,bar"></script>
Run Code Online (Sandbox Code Playgroud)
我想为我的CSS文件做同样的事情:
<link href="styles/css.php?build=123&load=foo,bar/jquery-ui-1.8rc2.custom" type="text/css">
Run Code Online (Sandbox Code Playgroud)
本css.php应该做的压缩方法:
<?php
error_reporting(E_ERROR);
// see http://web.archive.org/web/20071211140719/http://www.w3.org/2005/MWI/BPWG/techs/CachingWithPhp
// $lastModifiedDate must be a GMT Unix Timestamp
// You can use gmmktime(...) to get such a timestamp
// getlastmod() also provides this kind of timestamp for the last
// modification date of the PHP file itself
function cacheHeaders($lastModifiedDate) {
if ($lastModifiedDate) {
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModifiedDate) {
if (php_sapi_name()=='CGI') {
Header("Status: 304 Not …Run Code Online (Sandbox Code Playgroud) 我有以下C#代码,它应该将任意对象序列化为字符串,然后当然反序列化它.
public static string Pack(Message _message)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream original = new MemoryStream();
MemoryStream outputStream = new MemoryStream();
formatter.Serialize(original, _message);
original.Seek(0, SeekOrigin.Begin);
DeflateStream deflateStream = new DeflateStream(outputStream, CompressionMode.Compress);
original.CopyTo(deflateStream);
byte[] bytearray = outputStream.ToArray();
UTF8Encoding encoder = new UTF8Encoding();
string packed = encoder.GetString(bytearray);
return packed;
}
public static Message Unpack(string _packed_message)
{
UTF8Encoding encoder = new UTF8Encoding();
byte[] bytearray = encoder.GetBytes(_packed_message);
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream input = new MemoryStream(bytearray);
MemoryStream decompressed = new …Run Code Online (Sandbox Code Playgroud) 我一直在干扰C#中的一个想法来创建一个软件(用于伪个人使用),但遇到了实现问题.嗯......也许他们是我不知道的设计问题,但我只是简直无法弄清楚.
考虑我们有以下"数据库":
Foo + Bar = Foobar
Baz + Qux = Bazqux
Foobar + Bazqux = Foobarbazqux
Run Code Online (Sandbox Code Playgroud)
这些是用于创建所述项目的配方.使用一个和一个,我们创建一个结果,可以进一步成为另一个食谱的成分.FooBarFoobar
现在想我们需要找出该项目的完整配方Foobarbazqux.对于人类的思想和智慧,它相对容易:
We need Foobarbazqux
Foobarbazqux = Foobar + Bazqux
Foobar = Foo + Bar
Bazqux = Baz + Qux
Foobarbazqux = Foo + Bar + Baz + Qux
Run Code Online (Sandbox Code Playgroud)
当然,如果我们拥有所有成分,我们可以"运行" 配方,并按照上面几段的顺序创建项目并执行每个配方.(那样:我们首先创建Foobar,然后Bazqux将两者结合起来得到最终结果.)
但在现实的时候,数据库是很多大.我想这就是计算机应该进入的地方.通过一个可用的软件,机器可以轻松找到所有的成分和执行(制作)步骤并将其提供给用户,因此我们不需要通过所有条目来读取手.
我想下载一个远程文件并将其放在我的服务器目录中,其名称与原始文件的名称相同.我试着用file_get_contents($url).
问题是文件名不包含在内$url,它就像:www.domain.com?download=1726.这个URL给我,例如:myfile.exe,所以我想使用file_put_contents('mydir/myfile.exe');.
我怎么能检索文件名?我get_headers()在下载之前尝试过,但我只有文件大小,修改日期和其他信息,缺少文件名.
我有以下问题:我有一个PHP文件(standards.php),其中包含以下语句:
define('CONSTVAR', '/path/');
Run Code Online (Sandbox Code Playgroud)
现在,我有另一个名为的文件untitled.php,其中包含:
include ('standards.php');
echo CONSTVAR;
Run Code Online (Sandbox Code Playgroud)
这将导致页面/path/显示常量的值.
到目前为止一切都很好.
但是,当我把它standards.php放在我的另一个网站上并尝试从那里(使用include('http://mysite.eu/core/standards.php');命令)包含它时,它不起作用.常量保持为空,我也得到以下错误
警告:main(http://mysite.eu/core/standards.php)[function.main]:无法打开流:第28行/home/www/this.nl/core/untitled.php中的权限被拒绝
警告:main()[function.include]:无法打开"http://mysite.eu/core/standards.php"(include_path ='.:/ usr/local/php4/lib/php')/第28行的home/www/this.nl/core/untitled.php
allow_url_include也启用allow_url_fopen了.当我输入standards.php浏览器的完整URL时,我得到一个页面结果,所以这不是没有访问权限的问题,对吧?
这可能是什么问题?为什么常量应该是全局的,而不是从远程服务器包含时"继承"?
考虑一个生成表单的PHP脚本,该表单看起来像一个表,并且多次输出相同的重复行:

print('<form method="POST" action="index.php">
<table>
<tr>
<th>Row #</th>
<th><tt>name</tt></th>
<th><tt>value</tt></th>
</tr>');
for ( $i = 1; $i <= 4; $i++ )
{
print('<tr>
<th>' .$i. '</th>
<td><input type="text" name="name_' .$i. '" size="20"></td>
<td><input type="text" name="value_' .$i. '" size="4"></td>
</tr>');
}
print('</table>
<input type="submit" name="is_submit" value="Submit">
</form>');
Run Code Online (Sandbox Code Playgroud)
提交此表单时,$_POST数组将如下所示:
array (
'name_1',
'value_1',
'name_2',
'value_2',
'name_3',
'value_3',
'name_4',
'value_4',
'is_submit',
);
Run Code Online (Sandbox Code Playgroud)
我想做什么,它组织这个输入所以它看起来像这样:
array (
1 =>
array (
'name',
'value',
),
2 =>
array (
'name',
'value',
),
3 => …Run Code Online (Sandbox Code Playgroud) 以下是我的代码片段,我将屏幕宽度分配给变量$width.但是当我将它转换为整数并回显它时,0会返回.
$width = '<script> document.write(window.screen.width); </script>';
//if i echo $width it shows 1366 which is width of my screen
$height = '<script> document.write(window.screen.height); </script>';
echo "The height is = $height"."<br>The width is = ".$width;
$a = (int)($width);
echo $a;
Run Code Online (Sandbox Code Playgroud)
我要求指导这种转换完美.
考虑以下定义:
class Foo
{
string Asd;
List<int> Qwert;
public Foo(string Bar, List<int> Baz = null)
{
// Set up instance from parameters
this.Asd = Bar;
this.Qwert = Baz ?? new List<int>;
}
public Foo(string Qwop)
{
// Code which sets up the instance based on what Qwop is
// E.g.: take Asd and Qwert values from a previous storage
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我在Foo foo = new Foo("value");执行第二个构造函数时调用构造函数.
如何使编译器强制使用命名参数进行调用?因为两个构造函数的第一个参数都是a string,所以存在明显的模糊性.(无论如何,我无法逃避或解决这个问题,我们需要采取一种方式string.)
Foo foo = new Foo("value"); // NOT …Run Code Online (Sandbox Code Playgroud) 我有一个Parse error: syntax error, unexpected '.'.我检查了报告位置周围的线条,但我不明白为什么会抛出错误.有没有办法得到一个语法错误,该错误与PHP报告中找不到的行有什么关系?
显然发现错误的代码:
$current = "<a href='http://example.com/garrysmod/donate/donate.php?c=" .. $choice .. "&steam=" .. $steam_id .. "'>" .. $words .. "</a>";
Run Code Online (Sandbox Code Playgroud)
完整的未完成的代码可以在这里找到.
我正在学习PHP正则表达式,而且我遇到了一些我无法理解的问题.
本书以验证电子邮件地址为例.
if (ereg("^[^@]+@([a-z0-9\-]+\.)+[a-z]{2,4}$", $email))
Run Code Online (Sandbox Code Playgroud)
我不清楚这个表达的几个元素.
[^@]+@([a-z0-9\-]+\.)?php ×8
c# ×3
include ×2
algorithm ×1
ambiguous ×1
arguments ×1
arrays ×1
caching ×1
chmod ×1
compression ×1
config ×1
const ×1
css ×1
encoding ×1
ereg ×1
file ×1
filesystems ×1
forms ×1
header ×1
html ×1
javascript ×1
object ×1
oop ×1
optimization ×1
parsing ×1
python ×1
recursion ×1
regex ×1
solver ×1
stream ×1
struct ×1
syntax ×1
umask ×1
unix ×1