我正在寻找一个函数来计算字符串在文件中出现的次数,我尝试使用$count = preg_match_all("/String/", $file, $matches);但它返回Warning: preg_match_all() expects parameter 2 to be string, resource given.是否有任何函数允许我用文件而不是字符串来执行此操作,或者是否有任何方法将文件分配给字符串(我假设后者会慢得多)?
我有三个图像(320x480),我试图在我的Cocos2D应用程序中垂直滚动.
在我的初始化方法中,我有以下内容:
//adding background sprites
background = [CCSprite spriteWithFile:@"BG1.png"];
background2 = [CCSprite spriteWithFile:@"BG2.png"];
//position background sprites
background.position = ccp(size.width, size.height/2);
background2.position = ccp(size.width, size.height*2);
//schedule to move background sprites
[self schedule:@selector(scroll:)];
//adding them to the main layer
[self addChild:background z:0];
[self addChild:background2 z:0];
Run Code Online (Sandbox Code Playgroud)
这是我的滚动方法:
-(void) scroll:(ccTime)dt
{
//move 30*dt px vertically
background.position = ccp(background.position.x, background.position.y - 30*dt);
background2.position = ccp(background2.position.x, background.position.y - 30*dt);
//reset offscreen position
if (background.position.y < 290)
{
background.position = ccp(480/2, 480);
}else if (background2.position.y < 290) …Run Code Online (Sandbox Code Playgroud) 我正在设置一个函数,以检查users我的数据库中的表中是否存在传递的用户名.为此,我使用以下代码:
function usernameCheck($username) {
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$stmt = $con->prepare("SELECT username FROM users WHERE username = ':name'");
$stmt->bindParam(':name', $username);
$stmt->execute();
if($stmt->rowCount() > 0){
echo "exists!";
} else {
echo "non existant";
}
}
Run Code Online (Sandbox Code Playgroud)
但是,无论我尝试什么设置$username,我都无法得到任何exists!回报.我已经尝试改变它来检查一个额外的列,比如userID,但它仍然不起作用.我认为我的语法是正确的,但我是PDO的新手,所以我可能错过了一些容易修复的东西.
谢谢.