我如何告诉php创建一个目录,然后在该目录中创建另一个目录?
我在这里使用mkdir.我有一个名为images的文件夹.我需要在名为'user'的图像中创建一个文件夹,然后在用户名下创建一个名为'15'的文件夹.我可以一次创建名为user的文件夹.我怎么能一起做?
我目前正在搜索和替换这样的网页模板:
$template = <<<TEMP
<html>
<head>
<title>[{pageTitle}]</title>
</head>
[{menuA}]
[{menuB}]
[{bodyContent}]
</html>
<<<TEMP;
Run Code Online (Sandbox Code Playgroud)
以上内容放在一个单独的文件中.
然后,我做:
$template = str_replace("[{pageTitle}]",$pageTitle,$template);
$template = str_replace("[{menuA}]",$menuA,$template);
$template = str_replace("[{menuB}]",$menuB,$template);
$template = str_replace("[{bodyContent}]",$bodyContent,$template);
//Some 10 more similar to the above go here.
echo $template;
Run Code Online (Sandbox Code Playgroud)
问题是,总共有15个,就像上面那样.
有没有更好/更清洁/专业的方式来做到这一点(搜索和替换,或以不同的方式完成整个事情).我发现这非常混乱和不专业.
我下载并提取了GeoLite2-City.mmdb,GeoLite2-Country.mmdb.两者都在htdocs\geoip\
然后,我运行了这个脚本.麻烦的是,这件事有什么作用?什么require_once 'vendor/autoload.php';应该包含?我在这里遗漏了什么.我过去常常使用以.dat文件形式出现的旧版本,并且没有问题.这些.mmdb对我来说有点难以破解.我想要做的就是当用户在页面上使用搜索工具时,将国家代码,国家/地区名称和其他数据存储在数据库中.我怎么做到这一点?
我的测试页面取自网站
<?php
require_once 'vendor/autoload.php'; //What is this supposed to contain?
use GeoIp2\Database\Reader; // What is this too?
// This creates the Reader object, which should be reused across
// lookups.
$reader = new Reader($_SERVER['DOCUMENT_ROOT'].'\geoip\GeoIP2-City.mmdb'); // Where my DB resides
// Replace "city" with the appropriate method for your database, e.g.,
// "country".
$record = $reader->city('128.101.101.101');
print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->country->names['zh-CN'] . "\n"); // '??'
print($record->mostSpecificSubdivision->name . "\n"); …Run Code Online (Sandbox Code Playgroud) 我有这样的mysql表:
CREATE TABLE `posts` (
`post_id` INT(10) NOT NULL AUTO_INCREMENT,
`post_user_id` INT(10) NOT NULL DEFAULT '0',
`gen_id` INT(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`post_user_id`, `post_id`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM;
Run Code Online (Sandbox Code Playgroud)
当我做:
insert into posts (post_user_id) values (1);
insert into posts (post_user_id) values (1);
insert into posts (post_user_id) values (2);
insert into posts (post_user_id) values (1);
select * from posts;
Run Code Online (Sandbox Code Playgroud)
我明白了:
post_id | post_user_id | gen_id
1 1 0
2 1 0
1 2 0
3 1 0
Run Code Online (Sandbox Code Playgroud)
为每个唯一用户生成唯一的post_id.
我需要gen_id列为1 2 3 …
我目前使用类似下面的mysql语句来搜索帖子标题.
select * from table where title like %search_term%
但问题是,如果标题如下:Acme launches 5 pound burger并且用户搜索Acme,它将返回结果.但是如果用户搜索Acme burger或者Acme 5 pound,它将不返回任何内容.
当用户搜索多个单词时,有没有办法让它返回结果?LIKE在这里使用是正确的还是可以使用其他东西?
将json数组编码为可在URL查询字符串中使用的字母数字字符串的最佳方法是什么?
我需要一些简单但不容易破解的东西.我已经阅读了所有加密和解密文档.
我需要加密一个json数组例如:{"firstName":"John","lastName":"Doe"}类似的东西a14iw58swd33s541dg2k58kv3s4gvkjsdf33s9f3,所以它可以在url查询字符串中使用http://www.example.com/?v=a14iw58swd33s541dg2k58kv3s4gvkjsdf33s9f3.
我稍后会解密这个服务器端.由于它是URL的一部分,我不能拥有类似的东西ȃZ Vì§n‹ØfjÒ šçæ¹ä¯
什么是一个简单而安全的方法呢?
将这两个SQL语句合并为一个的最佳方法是什么?我尝试使用union,但似乎无处可去.
select id as id from likes where type=1;
select sum(votes) as votes from likes where parent=id;
Run Code Online (Sandbox Code Playgroud)
这是likes表格:
id type parent country votes
1 1 0 US 0
2 2 1 US 6 // This +
19 3 1 US 3 // This
3 3 2 US 3
7 3 2 US 3
4 10 3 US 1
5 10 3 US 1
6 10 3 US 1
10 10 7 US 1
9 10 7 US 1 …Run Code Online (Sandbox Code Playgroud) 我想用国家/地区代码和新的id自动增量值更新表中的列。
BEGIN
SET new.key = concat(new.countryCode,new.id);
END
Run Code Online (Sandbox Code Playgroud)
countryCode工作正常,但id总是空白。我怎样才能实现这样的目标?来自id专栏autoincrement。
我知道它不起作用,因为它是在插入后生成的。那么我怎样才能做这样的事情呢?
在PHP中,是否存在函数或其他任何函数将删除数组中与正则表达式不匹配的所有元素。
我的正则表达式是这样的: preg_match('/^[a-z0-9\-]+$/i', $str)
我的数组是从表单中输入的(实际上是标签)
来自表单的原始数组。注意:邪恶标签
$arr = array (
"french-cuisine",
"french-fries",
"snack-food",
"evil*tag!!",
"fast-food",
"more~evil*tags"
);
Run Code Online (Sandbox Code Playgroud)
清洗过的阵列。注意,没有邪恶的标签
Array (
[0] => french-cuisine
[1] => french-fries
[2] => snack-food
[3] => fast-food
)
Run Code Online (Sandbox Code Playgroud)
我目前确实喜欢这种方法,但是有更好的方法吗?也许没有循环?
foreach($arr as $key => $value) {
if(!preg_match('/^[a-z0-9\-]+$/i', $value)) {
unset($arr[$key]);
}
}
print_r($arr);
Run Code Online (Sandbox Code Playgroud)
我试图找出谷歌驱动器加载其文件夹内容的路径,从双击文件夹名称到加载该文件夹内容的位置。
我注意到谷歌使用类似的东西:
<div jsaction="click:cOuCgd; contextmenu:mg9Pef; dblclick:FNFY6c; focus:AHmuwe" jsname="LvFR7c" role="row" tabindex="0" aria-selected="false" aria-disabled="false">
Run Code Online (Sandbox Code Playgroud)
有什么作用dblclick:FNFY6c?是FNFY6c函数吗?这整个过程是如何运作的?我一直在尝试使用 Chromes DevTools 来弄清楚这是如何工作的,但似乎找不到FNFY6c任何地方。
我如何知道dblclick:FNFY6c单击时接下来会发生什么?
javascript google-closure-library google-closure-compiler google-chrome-devtools
php ×7
mysql ×4
sql ×4
arrays ×1
encryption ×1
geoip ×1
javascript ×1
maxmind ×1
regex ×1
replace ×1