小编Mat*_*att的帖子

GROUP_CONCAT()和CONCAT_WS()之间的区别?

我已经搜索不成功上的区别一个满意的解释GROUP_CONCAT()CONCAT_WS().

它们和我认为的密切相关吗?

这两个功能之间在使用,速度等方面有何不同?

mysql

20
推荐指数
2
解决办法
3万
查看次数

对于NSAttributedString,AutoLayout行高度计算错误

我的应用程序从API中提取HTML,将其转换为NSAttributedString(为了允许可点击的链接)并将其写入AutoLayout表中的一行.麻烦的是,每当我调用这种类型的单元格时,高度都会被错误计算并且内容会被切断.我尝试过不同的行高计算实现,但都没有正常工作.

如何准确,动态地计算其中一行的高度,同时仍保持点击HTML链接的能力?

不良行为的示例

我的代码如下.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch(indexPath.section) {
        ...
        case kContent:
        {
            FlexibleTextViewTableViewCell* cell = (FlexibleTextViewTableViewCell*)[TableFactory getCellForIdentifier:@"content" cellClass:FlexibleTextViewTableViewCell.class forTable:tableView withStyle:UITableViewCellStyleDefault];

            [self configureContentCellForIndexPath:cell atIndexPath:indexPath];
            [cell.contentView setNeedsLayout];
            [cell.contentView layoutIfNeeded];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.desc.font = [UIFont fontWithName:[StringFactory defaultFontType] size:14.0f];

            return cell;
        }
        ...
        default:
            return nil;
    }
}
Run Code Online (Sandbox Code Playgroud)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    UIFont *contentFont = [UIFont fontWithName:[StringFactory defaultFontType] size:14.0f];
    switch(indexPath.section) {
        ...
        case kContent:
            return [self textViewHeightForAttributedText:[self convertHTMLtoAttributedString:myHTMLString] andFont:contentFont andWidth:self.tappableCell.width];
            break;
        ...
        default:
            return …
Run Code Online (Sandbox Code Playgroud)

objective-c ios autolayout ios8

13
推荐指数
2
解决办法
6861
查看次数

使用preg_replace()将CamelCase转换为snake_case

我现在有一个方法将我的驼峰案例字符串转换为蛇案例,但它分为三个调用preg_replace():

public function camelToUnderscore($string, $us = "-")
{
    // insert hyphen between any letter and the beginning of a numeric chain
    $string = preg_replace('/([a-z]+)([0-9]+)/i', '$1'.$us.'$2', $string);
    // insert hyphen between any lower-to-upper-case letter chain
    $string = preg_replace('/([a-z]+)([A-Z]+)/', '$1'.$us.'$2', $string);
    // insert hyphen between the end of a numeric chain and the beginning of an alpha chain
    $string = preg_replace('/([0-9]+)([a-z]+)/i', '$1'.$us.'$2', $string);

    // Lowercase
    $string = strtolower($string);

    return $string;
}
Run Code Online (Sandbox Code Playgroud)

我编写了测试来验证其准确性,并且它可以正常使用以下输入数组(array('input' => 'output')):

$test_values = [
    'foo' …
Run Code Online (Sandbox Code Playgroud)

php regex preg-replace

10
推荐指数
1
解决办法
1899
查看次数

PHP邮件html格式无法正常工作

使用PHP,并使用此代码我收到电子邮件作为纯文本,我错过了什么?因为我需要发送格式化的电子邮件,例如可以包含链接.

$to = "receiver@test.com";
$subject = "Password Recovery";

$body = '
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Birthday Reminders for August</title>
    </head>
    <body>
        <p>Here are the birthdays upcoming in August!</p>
        <table>
            <tr>
                <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
            </tr>
            <tr>
                <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
            </tr>
            <tr>
                <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
            </tr>
        </table>
    </body>
</html>
';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From: info@test.net\r\n"."X-Mailer: php";
if (mail($to, $subject, $body, $headers)) 
echo "Password recovery instructions been sent to your email<br>";
Run Code Online (Sandbox Code Playgroud)

php email

7
推荐指数
2
解决办法
3万
查看次数

PHP改为mysqli.mysqli_connection不是全局的吗?

我刚刚开始一个新的PHP项目,我认为是时候关注php建议并停止使用mysql和swith来代替mysqli.但这给了我一个问题.

Normaly我的设置是这样的

Index.php文件和这个文件里面我有2个require语句.一个调用db.php文件,另一个调用functions.php文件.到现在为止还挺好.

在functions.php文件中,有很多不同的函数在整个主页上使用,其中很多都使用SQL.使用php旧的mysql API这没有问题,但它接缝新的mysqli api不允许从包含文件中使用连接???

例如在我的db.php中我有connect语句.$db = mysql_connect(*******); 在我的function.php中我有mysql_query(******)它并且它完美无缺.

但是,如果我$db = mysqli_connect(*****); 在我的function.php文件中将db.php更改为Then,我就无法调用mysqli_query(***).(我也测试了面向对象,但它给了我同样的问题).

那么如何解决这个问题呢?php是否希望我将mysqli_connect语句放在每个使用sql语句的文件的开头?

php mysql mysqli function

6
推荐指数
3
解决办法
2万
查看次数

模拟 HTTP 请求进行单元测试

我正在编写一个 MVC 框架,它利用一个库来帮助管理输入变量(例如 get、post 等)。

现在,我正在通过分别将 POST 和 GET 变量的值强制写入 $_POST 和 $_GET 超全局变量来测试 POST 和 GET 变量,但在测试 PUT 和 DELETE 请求变量时遇到了障碍。

例子:

public function testGET()
{
    $_GET['test'] = 'test value';

    $get_value = Input::get('test', '[default value]');

    assertEquals('test value', $get_value);
}
Run Code Online (Sandbox Code Playgroud)

是否有一个好方法来模拟/模拟这些变量或使用各种可用的方法(特别是 GET、POST、PUT、DELETE)来模拟 HTTP 请求?

php phpunit unit-testing httprequest

3
推荐指数
1
解决办法
4916
查看次数

PDO fetchAll()返回空数组

我正在使用PDO执行一个简单的查询,没有绑定参数.我已经直接对我的数据库进行了测试,它干净地执行,返回预期的结果.但是,当我将其插入我的PDO对象并调用时fetchAll(),它返回一个空数组.

$query = 'SELECT count(*) as mycount FROM mytable';
$mysql = $connection->prepare($query);
$result = $mysql->fetchAll();

print_r($result);
Run Code Online (Sandbox Code Playgroud)

预期结果:

array
(
    [mycount] => 8
)
Run Code Online (Sandbox Code Playgroud)

实际结果:

array
(
)
Run Code Online (Sandbox Code Playgroud)

可能导致此问题的任何想法,或者如何对此进行故障排除?

php mysql pdo

2
推荐指数
1
解决办法
3262
查看次数

安装红宝石宝石时超时

我正在尝试使用安装bundler gem $ gem install bundler.当我执行命令时,收到以下响应:

ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:
    Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Operation   timed out - connect(2) (https://api.rubygems.org/latest_specs.4.8.gz)
ERROR:  Possible alternatives: bundler
Run Code Online (Sandbox Code Playgroud)

为了确保我不会发疯,我尝试安装nokogiri:

ERROR:  Could not find a valid gem 'nokogiri' (>= 0), here is why:
  Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Operation timed out - connect(2) (https://api.rubygems.org/latest_specs.4.8.gz)
ERROR:  Possible alternatives: nokogiri
Run Code Online (Sandbox Code Playgroud)

和a2z:

ERROR:  Could not find a valid gem 'a2z' …
Run Code Online (Sandbox Code Playgroud)

ruby rubygems

2
推荐指数
4
解决办法
9516
查看次数

静态变量作为计数器

我正在编写一个jQuery插件,需要跟踪页面中使用该插件的对象数量.有没有办法在插件中创建一个跟踪自身实例的静态变量?

这是我到目前为止插件的内容:

(function ($) {
    $.fn.my_plugin = function (options)
    {
        var plugin_count = 0;

        return this.each(function() {
            alert(++plugin_count);
        });
    }
}(jQuery));
Run Code Online (Sandbox Code Playgroud)

在我的页面上:

<div class="plugin_div"></div>
<div class="plugin_div"></div>
<div class="plugin_div"></div>
<div class="plugin_div"></div>

<script language="javascript">
    $('.plugin_div').my_plugin();
</script>
Run Code Online (Sandbox Code Playgroud)

当页面加载时,我收到四个警报,显示"1".

我怎么写这个,以便变量为每个调用的元素递增my_plugin()

编辑:修复了糟糕的copypaste工作.

javascript jquery jquery-plugins

1
推荐指数
1
解决办法
1699
查看次数

切换评估

我最近讨论了如何switch处理比较,并需要帮助解决它.

如果我写了switch如下:

switch ($x){
    case ($x > 5):
        echo "foo";
        break;
    case ($x < 5):
        echo "bar";
        break;
    default:
        echo "five";
        break;
}
Run Code Online (Sandbox Code Playgroud)

哪个if陈述相当于?A还是B

// A

if ($x > 5) {
    echo "foo";
} elseif ($x < 5) {
    echo "bar";
} else {
    echo "five";
}

// B

if ($x == ($x > 5)) {
    echo "foo";
} elseif ($x == ($x < 5)) {
    echo "bar";
} else …
Run Code Online (Sandbox Code Playgroud)

php switch-statement

0
推荐指数
1
解决办法
317
查看次数

如何通过php条件销毁cookie

我想通过php条件销毁cookie但是在谷歌和php手册的大量研究之后我没有做任何事情.我在某个地方读过setcookie('cookie_name');但它只是擦除了cookie所以我的问题是如何通过php销毁cookie?

php cookies

0
推荐指数
1
解决办法
8430
查看次数

我该如何解决这个php mysql循环?

<?

$sql = dbquery("SELECT `id`, `title`, `description` FROM `content` LIMIT 0,12 ");
while ($row = mysql_fetch_array($sql)) {
    $id          = $row["id"];
    $title       = $row["title"];
    $description = $row["description"];
    $content     = '
    <div class="description-box">
    <p>page id: ' . $id . '</p>
    <p>' . $title . '</p>
    <p>' . $description . '</p>
    </div>';
}

echo $content;
?>
Run Code Online (Sandbox Code Playgroud)

// notice:div class ="description-box"

//如何在每3个输出div之后用以下代码替换:div class ="description-box nopadding"?

html生成代码示例:

<div class="description-box nopadding">
// content
</div>
<div class="description-box">
// content
</div>
<div class="description-box">
// content
</div>
<div class="description-box"> …
Run Code Online (Sandbox Code Playgroud)

php mysql

-1
推荐指数
1
解决办法
81
查看次数