需要检查$ message长度是否为7个字符或更少,如果是,请执行操作A,如果不是,请执行操作B.这是正确的语法吗?我觉得我做错了什么?
<?php
if (strlen($message) <= 7) {
echo $actiona;
} else {
echo $actionb;
}
?>
Run Code Online (Sandbox Code Playgroud) 我如何使用javascript(我假设)来克隆像下面图片中精美插图的表格行?
我正在使用以下代码为上传的文件生成唯一的文件名
$date = date( 'U' );
$user = $_SERVER[REMOTE_ADDR];
$filename = md5($date.$user);
Run Code Online (Sandbox Code Playgroud)
问题是我想稍后在脚本中再次使用这个文件名,但如果脚本需要一秒钟才能运行,我将在第二次尝试使用此变量时获得不同的文件名.
例如,我正在使用上传/调整大小/保存图像上传脚本.该脚本的第一个操作是复制并保存已调整大小的图像,我使用日期函数为其分配唯一的名称.然后脚本处理保存并保存整个上载,并为其指定名称.在脚本的末尾($thumb并且$full是变量),我需要在MySQL数据库中插入我保存上传时使用的文件名.
问题是,有时在大图像上需要一秒钟以上(或者在此过程中,秒数会发生变化),导致数据库中放入的文件名不同于文件实际保存的文件名.
使用这种命名方法这不是一个好主意吗?
我有一个文字标题
This User "The Title Of The Post"
Run Code Online (Sandbox Code Playgroud)
我想抓住INSIDE中的引号,并将其存储在变量中.我怎么用正则表达式和PHP做到这一点?
我可以将整个POST数组传递给函数并在函数内处理它吗?
如
PostInfo($_POST);
function PostInfo($_POST){
$item1 = $_POST[0];
$item2 = $_POST[1];
$item3 = $_POST[2];
//do something
return $result;
}
Run Code Online (Sandbox Code Playgroud)
或者这是正确的方法吗?
使用以下代码显示我的推特个人资料中的朋友列表.我喜欢一次只加载一定数量,比如说20,然后在第一个1-2-3-4-5的底部提供分页链接(不过很多除以限制)最后
$xml = simplexml_load_string($rawxml);
foreach ($xml->id as $key => $value)
{
$profile = simplexml_load_file("https://twitter.com/users/$value");
$friendscreenname = $profile->{"screen_name"};
$profile_image_url = $profile->{"profile_image_url"};
echo "<a href=$profile_image_url>$friendscreenname</a><br>";
}
Run Code Online (Sandbox Code Playgroud)
******更新******
if (!isset($_GET['i'])) {
$i = 0;
} else {
$i = (int) $_GET['i'];
}
$limit = $i + 10;
$rawxml = OauthGetFriends($consumerkey, $consumersecret, $credarray[0], $credarray[1]);
$xml = simplexml_load_string($rawxml);
foreach ($xml->id as $key => $value)
{
if ($i >= $limit) {
break;
}
$i++;
$profile = simplexml_load_file("https://twitter.com/users/$value");
$friendscreenname = $profile->{"screen_name"};
$profile_image_url = $profile->{"profile_image_url"};
echo "<a href=$profile_image_url>$friendscreenname</a><br>"; …Run Code Online (Sandbox Code Playgroud) 假设我想循环遍历XML节点但我想忽略前10个然后将我抓到的数量限制为10.
$limit=10; //define results limit
$o=20; //define offset
$i=0; //start line counter
foreach($xml->id AS $key => $value){
$i++;
if($i > $o){
//if line number is less than offset, do nothing.
}else{
if($i == "$limit"){break;} //if line is over limit, break out of loop
//do stuff here
}
}
Run Code Online (Sandbox Code Playgroud)
所以在这个例子中,id想要从结果20开始,并且只显示10个结果,然后突破循环.虽然不行.有什么想法吗?
我有一个使用ajax发布的表单并重新加载下面的div.
按下提交按钮时,我需要清除文本框.
<form name=goform action="" method=post>
<textarea name=comment></textarea>
<input type=submit value=submit>
</form>
Run Code Online (Sandbox Code Playgroud) 假设我在400处开始我的计数器.我将如何执行一个向后运行直到0的foreach循环?
伪代码
$i = 400;
foreach(**SOMETHING**)){
//do stuff
$i--;
}
Run Code Online (Sandbox Code Playgroud) 我不确定这叫什么,这就是为什么我在搜索它时遇到了麻烦.
我想要做的是取数字并将它们转换为一些字母数字基数,这样数字,比如5000,不会读作'5000'而是'G4u',或类似的东西.这个想法是为了节省空间,也没有明确给定系统中有多少记录.我正在使用php,所以如果有更好的内置这样的东西,甚至更好,但即使这个方法的名称将在这一点上有所帮助.
再次,抱歉没有能够更清楚,我只是不确定这叫什么.
php ×8
javascript ×2
jquery ×2
foreach ×1
html ×1
mootools ×1
pagination ×1
regex ×1
simplexml ×1