我使用这些代码行来删除所有标点符号,符号等,你可以在数组中看到它们,
$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)
但它没有删除得分不足 - _
删除所有这些东西的最佳方法是什么?正则表达能做到吗?
我一直在学习为我的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) 如何删除元素而不删除元素内的内容?
<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) 有什么区别.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)
什么时候使用哪种情况最好?
我可以设置context在Angularjs $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) 我们如何在 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 来做到这一点。
有任何想法吗?
我在运行的网站上有以下错误.我不明白为什么它在我的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) 为什么这行会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) 如何将大写字母串中每个单词的第一个字符接受一些我不想转换它们的单词,比如 - 和,等等?
例如,我想要这个 - ucwords('art and design')输出下面的字符串,
'艺术与设计'
是否有可能 - strip_tags($text, '<p><a>')我们允许
在字符串中?
或者我应该用别的东西?请指教!
谢谢.
$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) php ×5
javascript ×2
jquery ×2
mysqli ×2
ajax ×1
angularjs ×1
arrays ×1
backbone.js ×1
bind ×1
callback ×1
clean-urls ×1
css ×1
filter-input ×1
mysql ×1
php-5.5 ×1
preg-replace ×1
tailwind-css ×1