我必须知道..
是
$this->form_validation->set_value('first_name')
同样的
$this->input->post('first_name')
Run Code Online (Sandbox Code Playgroud)
?
他们似乎都得到了输入值.如果我验证输入,第一个更安全吗?
我找到了一些解决方案,但我无法决定使用哪种解决方案.array_unique()
在不区分大小写的数组上使用php 函数的最紧凑有效的解决方案是什么?
例:
$input = array('green', 'Green', 'blue', 'yellow', 'blue');
$result = array_unique($input);
print_r($result);
Run Code Online (Sandbox Code Playgroud)
结果:
Array ( [0] => green [1] => Green [2] => blue [3] => yellow )
我们如何删除副本green
?至于要删除哪一个,我们假设具有大写字符的重复是正确的.
例如,保持PHP
删除php
或保持PHP
删除,Php
因为PHP
有更多的大写字符.
结果将是
Array ( [0] => Green [1] => blue [2] => yellow )
请注意,已保留带大写的绿色.
选项
$lat = '25.7742658';
$lng = '-80.1936589';
$miles = 30;
Run Code Online (Sandbox Code Playgroud)
询问
SELECT *,
( 3959 * acos( cos( radians($lat) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians($lng) )
+ sin( radians($lat) )
* sin( radians( lat ) ) ) ) AS distance
FROM locations
HAVING distance < $miles
ORDER BY distance
LIMIT 0, 20
Run Code Online (Sandbox Code Playgroud)
我有一个包含4列的数据库表:
我在顶部使用查询返回指定坐标内指定英里数内的位置.它似乎工作,但我不确定它是多么准确.我很高兴知道查询是好还是你有更好的解决方案.
我正在尝试在网站上创建一个用于私人消息传递的表.我创建了下表,我认为这是有效的,但我真的很感激一些反馈.
CREATE TABLE IF NOT EXISTS `pm` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`to` int(11) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`subject` varchar(255) DEFAULT NULL,
`message` text NOT NULL,
`read` tinyint(1) NOT NULL DEFAULT '0',
`deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
FOREIGN KEY (user_id) REFERENCES User(user_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Run Code Online (Sandbox Code Playgroud)
我有2列确定消息的状态:read
和deleted
如果read = 1
,接收方已读取该消息.如果deleted = 1
发件人或收件人从发送或收到的收件箱中删除了邮件.如果deleted = 2
两个用户都删除了该消息,则从数据库表中删除该行.
我想[gallery]
在我的博文中删除短代码.我发现的唯一解决方案是我添加到我的函数中的过滤器.
function remove_gallery($content) {
if ( is_single() ) {
$content = strip_shortcodes( $content );
}
return $content;
}
add_filter('the_content', 'remove_gallery');
Run Code Online (Sandbox Code Playgroud)
它删除了所有短代码,包括[caption]
我需要的图像.如何指定要排除或包含的单个短代码?
我需要创建一个时间数组,我将在HTML下拉列表中使用.数组键应为24小时格式,值为12小时,am和pm.在数据库中我想存储24h格式.有没有快速的方法来创建数组而不是每小时输入?
例:
'00:00:00' => '12:00am',
'01:00:00' => '1:00am',
etc
Run Code Online (Sandbox Code Playgroud) 我正在使用Codeigniter的文件上传类来上传用户头像.有没有办法在用户上传新文件时替换用户的图像文件?我想用最新上传的头像替换现有头像.
我的图片上传控制器
function upload_avatar()
{
$config['upload_path'] = './uploads/avatars/';
$config['allowed_types'] = 'jpg|png';
$config['overwrite'] = FALSE; //overwrite user avatar
$config['encrypt_name'] = TRUE;
$config['max_size'] = '200'; //in KB
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = $this->upload->display_errors();
$this->session->set_flashdata('error', $error);
redirect('/settings/avatar');
}
else
{
$config['image_library'] = 'gd2';
$config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = FALSE;
$config['width'] = 120;
$config['height'] = 120;
$this->load->library('image_lib', $config);
$this->image_lib->crop();
//Add image path to database
$avatar_path = 'uploads/avatars/' . $this->upload->file_name;
$user_id = $this->tank_auth->get_user_id();
$this->Settings_model->update_avatar($avatar_path, $user_id);
$this->session->set_flashdata('success', …
Run Code Online (Sandbox Code Playgroud) 我正在使用Gutenberg块过滤器尝试在编辑器中为块的包装器组件添加动态类名.
registerBlockType( name, {
title: __( 'My Block' ),
parent: [ 'myplugin/myblock' ],
category: 'common',
attributes: attributes,
edit( { attributes, setAttributes, className } ) {
const { someName } = attributes;
/* how can I pass someName from here to customClassName? */
return (
/* render something */
);
},
save( { attributes } ) {
const { someName } = attributes;
/* how can I pass someName from here to customClassName? */
return (
/* render something …
Run Code Online (Sandbox Code Playgroud) 我正在尝试执行以下操作:
我有一个输入 <input type="text" value="red,yellow,blue" id="colors" />
和下拉列表
<select name="colors_dropdown" id="colors_dropdown">
<option value="red">red</option>
<option value="yellow">yellow</option>
<option value="blue">blue</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我想删除文本输入中的选择选项.例如,如果文本输入value=red,blue
下拉列表应该只有选项yellow
.
我能够在文本输入中创建逗号分隔值的数组,并在下拉选项中创建值.
var selected_colors = $('#colors').val().split(","); //array of colors from text input
var all_colors = $.map($("#colors_dropdown")[0].options, function(option)
{
return option.value; //array of all colors from dropdown
});
Run Code Online (Sandbox Code Playgroud)
基于此,我正在寻找一种方法来填充下拉列表中的所有颜色,除了selected_colors
数组中的颜色.
我正在尝试使用 ActiveRecord 在 CI 中创建以下查询
SELECT *,
( 3959 * acos( cos( radians($lat) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians($lng) )
+ sin( radians($lat) )
* sin( radians( lat ) ) ) ) AS distance
FROM locations
HAVING distance <= $miles
ORDER BY distance
LIMIT 0, 20
Run Code Online (Sandbox Code Playgroud)
我试过
$where = "( 3959 * acos( cos( radians($lat) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians($lng) ) + sin( …
Run Code Online (Sandbox Code Playgroud)