是否可以在the_content()
执行之前从内容中删除图库短代码?我搜索了codex remove_shortcode( $tag )
但发现它们没有显示任何例子.
我尝试添加功能
function remove_gallery($content) {
$content .= remove_shortcode('[gallery]');
return $content;
}
add_filter( 'the_content', 'remove_gallery', 6);
Run Code Online (Sandbox Code Playgroud)
它不起作用..
更新:
我能够使用下面的代码取消注册短代码,但它也删除了内容
function remove_gallery($content) {
return remove_shortcode('gallery', $content);
}
add_filter( 'the_content', 'remove_gallery', 6);
Run Code Online (Sandbox Code Playgroud) 我在解决这个问题时遇到了一些麻烦.
我有以下CSV字符串
hello world, hello world, hello
Run Code Online (Sandbox Code Playgroud)
中间值有多余的空格.我正在修剪它
preg_replace('/( )+/', ' ', $string)
Run Code Online (Sandbox Code Playgroud)
该函数非常出色,但它也删除了逗号后面的空格.它成为了..
hello world,hello world,hello
我想在逗号之后保留1个空格
hello world, hello world, hello
我怎样才能做到这一点?
编辑:
preg_replace('/(?<!,) {2,}/', ' ', $string);
按照建议使用,但我遇到了另一个问题.当我在逗号后使用多于1个空格时,它会在逗号后面返回2个空格.
所以
hello world, hello world,hello
Run Code Online (Sandbox Code Playgroud)
回报
hello world, hello world, hello
Run Code Online (Sandbox Code Playgroud)
作为解决方案,我从CSV字符串创建一个数组并使用 implode()
$string = "hello world, hello world,hello";
$val = preg_replace('/( )+/', ' ', $string);
$val_arr = str_getcsv($val); //create array
$result = implode(', ', $val_arr); //add comma and space between array elements
return $result; // Return the value …
Run Code Online (Sandbox Code Playgroud) 在Model类中,我return $query->row();
用来返回单行和return $query->result();
返回多行时.
在单个页面上,我必须从2个单独的表中返回单行和多行.
表users
包含一般信息,如用户名,全名和电子邮件地址.表user_links
包含相应用户提交的链接,每个用户有多行.
我的查询
$this->db->select('*');
$this->db->from('users');
$this->db->join('user_links', "user_links.user_id = users.user_id");
$this->db->where('users.user_id', $user_id);
$this->db->where('user_links.user_id', $user_id);
$query = $this->db->get();
return $query->row();
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我在我的视图中加载查询
$data['row'] = $this->User_model->user_read($user_id);
,
$user_id
是包含唯一用户ID的第3个URL段.
最后,在我的视图中,我检索行 echo $row->first_name;
这适用于单行,但如何foreach
为用户链接创建循环?目标是避免单行循环,并仅将其用于检索多行.
我在我的PHP脚本中使用时间戳来处理小时,分钟和秒的时间.时间戳也记录了日期,但我只是在使用时间00:00:00
.
例如,我在时间上有所不同
$start = strtotime("12:00:00");
$end = strtotime("20:00:00");
$difference = $end - $start;
Run Code Online (Sandbox Code Playgroud)
或划分时间
$divide = $difference/3;
我应该继续使用时间戳进行这些操作还是在PHP中有特定于时间的功能?
我找不到任何关于此的文件.我上传图片并使用
$config['create_thumb'] = TRUE;
Run Code Online (Sandbox Code Playgroud)
创建一个拇指并保留原始图像.
有没有办法获取拇指图像的文件名?_thumb
在缩略图的名称中自动添加,但没有提取全名的功能.
我正在使用Ajax访问字典REST API.
$.ajax({
url: "http://api.wordnik.com//v4/word.json/cat/definitions?api_key=mykey&includeRelated=false&includeTags=false&limit=1",
dataType : 'json',
success: function(data) {
//called when successful
alert(data.word);
},
error: function(e) {
//called when there is an error
console.log(e.message);
}
});
Run Code Online (Sandbox Code Playgroud)
响应:
[
{
"textProns": [],
"sourceDictionary": "ahd-legacy",
"exampleUses": [],
"relatedWords": [],
"labels": [],
"citations": [],
"word": "cat",
"text": "A small carnivorous mammal (Felis catus or F. domesticus) domesticated since early times as a catcher of rats and mice and as a pet and existing in several distinctive breeds and varieties.",
"sequence": "0", …
Run Code Online (Sandbox Code Playgroud) 我将我的文件上传到网络存储服务,所以我不需要将它们存储在我的服务器中.我想将它们存储在一个临时文件夹中,但也使用Codeigniter的上传类进行安全验证和文件名加密.
我在配置中尝试了这个
$config['upload_path'] = $_FILES['userfile']['tmp_name'];
$this->load->library('upload', $config);
$this->upload->do_upload();
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误的上传路径错误.是否可以在不创建自己的上传类的情况下上传临时文件?
我有一个存储的数组 data()
$('body').data('my-array', [red, blue, orange, green]);
Run Code Online (Sandbox Code Playgroud)
从阵列中获取倒数第二项的最快方法是什么?在这种情况下orange
.
我试过了:
$('body').data('my-array').get(-2);
Run Code Online (Sandbox Code Playgroud)
并获得$(...).data(...).get
不是一个功能.
注意:我发现了类似的问题但与数组无关data()
.请在标记为重复之前检查.
我正在使用Object.assign()
将值复制到对象:
const { one, two, three } = attributes;
return Object.assign( props, {
"data-one": one,
"data-two": two,
"data-three": three
} );
Run Code Online (Sandbox Code Playgroud)
如果属性的值为空,则返回undefined.我希望它返回一个空字符串或理想情况下不复制任何空属性.
我试过这个:
const { one, two, three } = attributes;
var oneValue = one ? one : "";
var twoValue = two ? two : "";
var threeValue = three ? three : "";
return Object.assign( props, {
"data-one": oneValue,
"data-two": twoValue,
"data-three": threeValue
} );
Run Code Online (Sandbox Code Playgroud)
它的工作原理是发送空值而不是未定义,但似乎不是很花哨.有没有更好的方法来处理这个?
是否可以使用 jquery 属性包含选择器$(this)
?我找不到任何例子。我正在尝试查看输入字段是否包含某个单词。
$("#form input").keyup(function() {
if ($(this).filter( "[name~='someWord']" )) {
console.log('yes');
}
});
Run Code Online (Sandbox Code Playgroud)
代码为所有输入返回 yes,即使它们不包含someWord
.
php ×5
codeigniter ×3
javascript ×3
jquery ×3
arrays ×2
file-upload ×2
function ×2
ajax ×1
api ×1
date ×1
ecmascript-6 ×1
filter ×1
html ×1
json ×1
mysql ×1
shortcode ×1
string ×1
time ×1
wordpress ×1