我怎样才能获得上周的PHP日期范围?
看下面的代码:
<?php
function get_last_week_dates(){
// how can i get the date range last week ?
// ex: today is 2014-2-8
// the week date range of last week should be '2014-1-26 ~ 2014-2-1'
}
?>
Run Code Online (Sandbox Code Playgroud) 如何在字符串中删除"\n"?
我用了3个方法,只有"\ s +"的接缝有效,但我只想删除\n,不是所有的空间,如何做这个工作?
需要帮助,这个问题困扰了我很长一段时间.
$str="<p>
hello<br>
world
</p>";
//$str=str_replace("\n","",$str);
$str=preg_replace("@\n@","",$str);
//$str=preg_replace("@\s+@"," ",$str);
echo $str;
Run Code Online (Sandbox Code Playgroud) 如何管理常量?
我在我的网站上使用zencart.
我将所有全局常量添加到:
includes/languages/english/english.php
Run Code Online (Sandbox Code Playgroud)
我的内容在我的任何页面中使用,例如:
includes/modules/meta_tags.php
Run Code Online (Sandbox Code Playgroud)
问题是,有些日子我从任何php文件中删除一个常量,但我不会在english.php中删除它.
一次又一次,我不知道english.php中的常量是什么,它们在哪里使用.
有没有办法知道在php文件中使用了什么常量?
<?php
// includes/languages/english/english.php
define('HELLO','hello');
define('WORLD','world');
?>
<?php
// includes/modules/meta_tags.php
echo HELLO;
?>
<?php
// includes/modules/product_listing.php
echo WORLD;
?>
Run Code Online (Sandbox Code Playgroud) 如何排序与数据库数据相同的数组?
我要求谷歌分析数据,数据是一个大型数组,我想从我的本地数据库加入数组与其他一些字段,然后我再次扩展大数组.现在我想对使用我的sql的大数组进行排序,如下所示:
select * from ga_table where ...
select * from ga_table order by age
select * from ga_table group by name
Run Code Online (Sandbox Code Playgroud)
我的阵列现在就像:
$arr=array(
'header'=>array('name','age','money'),
'values'=>array(
array('jimmy',20,30),
array('tina',18,12),
array('darcy',19,50),
)
);
Run Code Online (Sandbox Code Playgroud)
但是现在我有一个大型数组而不是db表,那么如何对数组进行排序?

考虑以下示例:
<?php
class p{
public $name = 'jimmy';
public $sex = 'male';
private $age = 31;
// there should be more unknow properties here ..
function test(){
echo $this->name;
}
function get_p_as_json(){
// how can i get json of this class which contains only public properties ?
// {"name":"jimmy","sex":"male"}
}
}
$p = new p();
$json = $p->get_p_as_json();
echo $json;
Run Code Online (Sandbox Code Playgroud)
问题: 如何获取班级的所有公共属性JSON?
如何将单个php文件中定义的所有常量都添加到数组中?
这是一个定义常量的php文件.
我想把这个页面中的所有常量都放到一个数组中;
我该怎么办?
<?php
/**
* hello wolrd
----------------------------------------
*/
define('HELLO_WORLD','hello world');
define('GOOD_BOOD','
very good
');
define(
'JY_CREDITS_HTML',
'
<p>hello wrold</p>
<div class="good">
<span>world</span>
</div>
'
);
// define('META_KEY','Wat adidi');
define('XXX',"xxx")
/*
hello world
*/
?>
Run Code Online (Sandbox Code Playgroud)
结果应该是
<?php
$result=array(
'HELLO_WORLD' => 'hello wrold',
'GOOD_BOOD' => 'very good',
'JY_CREDITS_HTML' =>'....',
'XXX'=>'xxx'
);
?>
Run Code Online (Sandbox Code Playgroud) 如何在php中获取包含所有英文字符的数组?
一种方法是在阵列中完全写下所有26个字母,但这看起来很愚蠢.
任何PHP功能或其他方式来完成这项工作?
<?php
// stupid ?
$arr= array('a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z');
?>
Run Code Online (Sandbox Code Playgroud) 如何删除div的可拖动事件?
我想在容器中添加新的.point,然后draggablge它,但首先我要取消绑定所有可拖动的$('.piont')事件,怎么做?
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.8.2/jquery-ui.js"></script>
<style type="text/css">
*{margin:0;padding:0}
.container{
margin:50px;
width:100px;
height:100px;
border:1px solid #777;
position:relative
}
.point{
width:20px;
height:20px;
background-color:tan;
position:absolute;
}
</style>
<script type="text/javascript">
$(function(){
$('.point').draggable({
stop: function (e){
alert(1);
}
});
});
function unbind_draggable(){
// how can unbind draggable for .point?
}
</script>
<div class="container">
<div class="point"></div>
<div class="point"></div>
<div class="point"></div>
<div class="point"></div>
</div>
<button onclick="unbind_draggable()">unbind_draggable</button>
Run Code Online (Sandbox Code Playgroud)

想象一下喜欢或投票页面的按钮.我需要这个按钮来发送Ajax请求来记录用户的喜欢.
点击按钮的人很快很多次,导致一些Ajax请求.
我该如何解决这个问题?
当人们单击按钮(span)时,我需要阻止它再次发送Ajax请求,直到完成上一个Ajax请求
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<span onclick="send_ajax(this)">send_ajax</span>
<script type="text/javascript">
function send_ajax(node){
$.ajax({
url:'ajax.php',
type:'POST',
data: {},
success:function() {
}
});
}
</script>
Run Code Online (Sandbox Code Playgroud) 我如何检查 js 链 var 是否存在?任何简单的检查方法,或使用 jquery
请参阅下面的代码:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
// how can i check a var exists ?
// the code bellow will return undefined
// a is undefined
// a.b is undefined --- when a exists, then I need to check a.b
// a.b.c is undefined ...
// a.b.c.d is undefined
// sometimes I need to check if some property of an object exists or is true, and I don't even know the object exists or …Run Code Online (Sandbox Code Playgroud) 如何获得cccc结果?
c是带有children属性和方法的obj,我想用c.method运行其他函数,比如bellow,我怎样才能得到与c.test()相同的结果?
<script type="text/javascript">
function a(fn){
fn();
}
function b(){
alert('bbbb');
}
var c={
name: 'cccc',
test: function (){
alert(this.name);
}
}
a(b); // get 'bbbb';
a(c.test); // get empty string, how can i get 'cccc'?
</script>
Run Code Online (Sandbox Code Playgroud) 如何在jquery中将所有输入字段值获取到数组?
请看下面的代码:
<input type="text" name="a" value="a" />
<input type="text" name="b" value="hello" />
<input type="text" name="c" value="world" />
<script type="text/javascript">
function get_fields_values(){
// too much code
var arr=[];
$.each($("input"),function(i,n){
arr.push(n.value)
});
return arr;
// is there any jquery method to get fields values to an array?
// $('input').xxx() ?
}
</script>
Run Code Online (Sandbox Code Playgroud)