小编lau*_*kok的帖子

删除标点符号,符号,变音符号,特殊字符的最佳方法是什么?

我使用这些代码行来删除所有标点符号,符号等,你可以在数组中看到它们,

$pattern_page = array("+",",",".","-","'","\"","&","!","?",":",";","#","~","=","/","$","£","^","(",")","_","<",">");

$pg_url = str_replace($pattern_page, ' ', strtolower($pg_url));
Run Code Online (Sandbox Code Playgroud)

但是我想让它变得更简单,因为在列表中列出我要删除的所有东西看起来很傻,因为我可能会删除一些其他特殊字符.

我想过使用下面的正则表达式,

$pg_url = preg_replace("/\W+/", " ", $pg_url);
Run Code Online (Sandbox Code Playgroud)

但它没有删除得分不足 - _

删除所有这些东西的最佳方法是什么?正则表达能做到吗?

php preg-replace special-characters clean-urls

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

如何在PHP中动态绑定mysqli bind_param参数?

我一直在学习为我的sql查询使用预备语句和绑定语句,到目前为止我已经提出了这个问题,但是它工作正常但是当涉及到多个参数或者当不需要参数时它根本不是动态的,

public function get_result($sql,$parameter)
    {
        # create a prepared statement
    $stmt = $this->mysqli->prepare($sql);

        # bind parameters for markers
    # but this is not dynamic enough...
        $stmt->bind_param("s", $parameter);

        # execute query 
        $stmt->execute();

    # these lines of code below return one dimentional array, similar to mysqli::fetch_assoc()
        $meta = $stmt->result_metadata(); 

        while ($field = $meta->fetch_field()) { 
            $var = $field->name; 
            $$var = null; 
            $parameters[$field->name] = &$$var; 
        }

        call_user_func_array(array($stmt, 'bind_result'), $parameters); 

        while($stmt->fetch()) 
        { 
            return $parameters;
            //print_r($parameters);      
        }


        # close statement
        $stmt->close();
    }
Run Code Online (Sandbox Code Playgroud)

这就是我调用对象类的方式,

$mysqli = new …
Run Code Online (Sandbox Code Playgroud)

php arrays mysqli bind prepared-statement

14
推荐指数
4
解决办法
3万
查看次数

如何删除元素而不删除其中的内容?

如何删除元素而不删除元素的内容?

<a href="#">
    <span>
        <img src="pic-1.jpg"/>
    </span>
</a>
Run Code Online (Sandbox Code Playgroud)

我想删除span一个封装图像.

所以我可以得到,

<a href="#">

    <img src="pic-1.jpg"/>

</a>
Run Code Online (Sandbox Code Playgroud)

jquery

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

Backbonejs:.on vs .listenTo vs .bind

有什么区别.on,.listenTo,和.bind

我在这里测试了它们,它们看起来做同样的事情:回调.

var NewStatusView = Backbone.View.extend({

    events: {
        "submit form": "addStatus"
    },

    initialize: function(options) {

        // using .on
        //this.collection.on("add", this.clearInput, this);

        // or using bind: 
        //_.bindAll(this, 'addStatus', 'clearInput');
        //this.collection.bind('add', this.clearInput);

        // or using listenTo: 
         _.bindAll(this, 'addStatus', 'clearInput');
        this.listenTo(this.collection, 'add', this.clearInput) ;
    },

    addStatus: function(e) {
        e.preventDefault();
        this.collection.create({ text: this.$('textarea').val() });
    },

    clearInput: function() {
        this.$('textarea').val('');
    }
});
Run Code Online (Sandbox Code Playgroud)

什么时候使用哪种情况最好?

javascript callback backbone.js

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

Angularjs $ http VS jquery $ .ajax

我可以设置contextAngularjs $http,就像我们可以做到这一点jQuery's $.ajax

define([
    'app'
], function(app) {

    app.controller("controller1", function($scope, $route, $http) {

        return $http({
            method: 'GET',
            url: 'server.php'
        }).then(function(response) {
            $scope.contacts = response.data;
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

另外,jQuery中还有更多的回调$.ajax,比如.done,.promise我可以用它来操作context下面这样的,我想知道我是否可以这样做Angularjs

$.ajax({
    type:       "GET",
    dataType:   "HTML",
    url:        'server.php',
    context:    $("#container"),
    async:      true,
    beforeSend: function() {

        $(this).html('loading...');
    },
    success: function (returndata, status, jqxhr) {
        $(this).html(returndata).hide().fadeIn();
    },
    }).fail(function() { 
        alert("error"); 
    }).done(function(returndata) {
    },
    .always(function() { 
        alert("complete"); 
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery angularjs

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

Tailwind CSS:如何在填充中使用自定义百分比?

我们如何在 Tailwind CSS 中的填充上使用自定义百分比?

我的配置:

theme: {
    extend: {
      spacing: {
        '80\%': '80%', // p-80% - doesn't work
      }
    },
  },
Run Code Online (Sandbox Code Playgroud)

我们可以用简单的 CSS 以旧的方式实现这一点:

.p-80\% {
   padding: 80%;
}
Run Code Online (Sandbox Code Playgroud)

但理想情况下,我们也可以使用 Tailwind 来做到这一点。

有任何想法吗?

css tailwind-css

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

MYSQLi错误:用户已经有超过'max_user_connections'的活动连接

我在运行的网站上有以下错误.我不明白为什么它在我的localhost上工作正常.这与主持人有关吗?我在Unix服务器上.

Warning: mysqli::mysqli() [mysqli.mysqli]: (42000/1203): User dbo343879423 already has more than 'max_user_connections' active connections in /homepages/9/d322397966/htdocs/dump/models/class_database.php on line 11
Connect failed: User dbo343879423 already has more than 'max_user_connections' active connections 
Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in /homepages/9/d322397966/htdocs/dump/models/class_database.php on line 160
Run Code Online (Sandbox Code Playgroud)

错误显示'用户dbo343879423已经在第11行的/homepages/9/d322397966/htdocs/dump/models/class_database.php中有超过'max_user_connections'活动连接,所以这是脚本中的第11行 - 我可以'看错了!

$this -> connection = new mysqli($hostname,$username,$password,$database);
Run Code Online (Sandbox Code Playgroud)

下面是class_database.php中的整个类,在脚本的其他部分是不对的,我应该改变?

<?php
#connects the database and handling the result
class __database {

    protected $connection = null;
    protected $error = null;

    #make a connection
    public function __construct($hostname,$username,$password,$database)
    {
        $this -> connection …
Run Code Online (Sandbox Code Playgroud)

php mysql error-handling mysqli

13
推荐指数
4
解决办法
7万
查看次数

PHP filter_input(INPUT_SERVER,'REQUEST_METHOD')返回null?

为什么这行会null在我的实时服务器中返回?

filter_input(INPUT_SERVER, 'REQUEST_METHOD');
Run Code Online (Sandbox Code Playgroud)

实时服务器是php5.5.9

我错过了什么吗?

我以为它用于替换下面的全局方法?

$_SERVER['REQUEST_METHOD'];
Run Code Online (Sandbox Code Playgroud)

一些代码,

public function __construct()
    {
        // Construct other generic data.
        $this->clientRequestMethod = filter_input(INPUT_GET, 'method'); // such as list, add, update, etc
        $this->clientPostMethod = filter_input(INPUT_POST, 'method'); // such as update
        $this->serverRequestMethod = filter_input(INPUT_SERVER, 'REQUEST_METHOD'); //such as get or post
    }


    public function processEntry()
    {

        // Determine the $_SERVER['REQUEST_METHOD'] whether it is post or get.
        if ($this->serverRequestMethod === 'POST' && $this->clientPostMethod != null) 
        {
            $this->processPost();
        }
        else if($this->serverRequestMethod === 'GET' && $this->clientRequestMethod …
Run Code Online (Sandbox Code Playgroud)

php filter-input

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

大写字符串中每个单词的第一个字符,除了'和','到'等

如何将大写字母串中每个单词的第一个字符接受一些我不想转换它们的单词,比如 - 和,等等?

例如,我想要这个 - ucwords('art and design')输出下面的字符串,

'艺术与设计'

是否有可能 - strip_tags($text, '<p><a>')我们允许

在字符串中?

或者我应该用别的东西?请指教!

谢谢.

php

12
推荐指数
5
解决办法
1万
查看次数

PHP array_column - 如何保存密钥?

    $items = array(
        1 => [
            "id" => 5
        ],

        3 => [
            "id" => 6
        ],
        4 => [
            "id" => 7
        ],
    );

    var_dump(array_column($items,"id"));
Run Code Online (Sandbox Code Playgroud)

结果,

array (size=3)
  0 => int 5
  1 => int 6
  2 => int 7
Run Code Online (Sandbox Code Playgroud)

但是我怎么能保持钥匙,$items所以我可以在下面得到这个?

array (size=3)
  1 => int 5
  3 => int 6
  4 => int 7
Run Code Online (Sandbox Code Playgroud)

multidimensional-array php-5.5

12
推荐指数
5
解决办法
1万
查看次数