我想设置AllowOverride all但我不知道该怎么做.我通过搜索谷歌找到了以下代码并将其粘贴在.htaccess中
<Directory>
AllowOverride All
</Directory>
Run Code Online (Sandbox Code Playgroud)
但在粘贴之后我开始收到了 .htaccess
可以任何人指导我在哪里放置此代码或如何做到这一点?
我打算mysqli_close($connection)用来关闭$connection.但在结束之前,我需要确保相关的连接是开放的.
我试过了
if($connection)
{
mysqli_close($connection);
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.任何方案?
我试图获得这个unicode字符串的长度
$text = '??? ????? ?';
$length = strlen($text);
echo $length;
Run Code Online (Sandbox Code Playgroud)
产量
20
Run Code Online (Sandbox Code Playgroud)
它如何确定unicode字符串的长度?
我有这样的查询
$query = "SELECT * FROM tbl_comments WHERE id=222 ORDER BY comment_time";
Run Code Online (Sandbox Code Playgroud)
我是否需要在该comment_time字段上添加索引?
另外,如果我想在两个日期之间获取数据,那么我应该如何构建索引?
我想明白mysqli_store_result实际上是做什么的?当我访问PHP手册时mysqli_store_result,我发现了definiton
mysqli_store_result — Transfers a result set from the last query
Run Code Online (Sandbox Code Playgroud)
问题是它转移结果集的位置?实际上我"Commands out of sync; you can't run this command now"在执行后得到错误mysqli_multi_query但是当我使用以下方法时,错误消失了.
mysqli_multi_query($connection,$query);
do
{
mysqli_store_result($connection);
}
while(mysqli_next_result($connection));
Run Code Online (Sandbox Code Playgroud)
现在,我应该使用它mysqli_store_result($connection),mysqli_next_result($connection)之后mysqli_query或之后mysqli_multi_query因为我已经阅读过PHP Manaul了
"尽管使用mysqli_free_result()函数释放查询结果所使用的内存总是好的做法,但在使用mysqli_store_result()传输大型结果集时,这一点变得尤为重要."
还有一个问题当我执行上面提到的时候,mysqli_multi_query($connection,$query);我发表了echo 'storing result <br />'如下的声明
do
{
echo 'storing result <br />
mysqli_store_result($connection);
}
while(mysqli_next_result($connection));
Run Code Online (Sandbox Code Playgroud)
虽然$ query中只有两个INSERT查询,但它给出了以下输出
storing result
storing result
storing result
storing result
Run Code Online (Sandbox Code Playgroud)
这意味着有四个结果集被转移.我无法理解这种情况.最后一个问题.上述 …
我使用CKEditor让用户发表评论,用户也可以将unicode字符放在评论框中.
当我提交表格并检查$ _POST ["回复"]时,unicode字符显示得非常好.我也在header('Content-type:text/html; charset=utf-8');页面顶部使用但是当我使用PHP DOMDocument处理它时,所有字符都变得不可读.
$html_unicode = "xyz unicode data";
$html_data = '<body>'.$html_unicode . '</body>';
$dom = new DOMDocument();
$dom->loadHTML($html_data );
$elements = $dom->getElementsByTagName('body');
Run Code Online (Sandbox Code Playgroud)
当我回声
echo $dom->textContent;
Run Code Online (Sandbox Code Playgroud)
输出变为
§Ø³ÙبÙÙ ÙÙÚº ØºØ±ÙØ¨ ک٠آÙÛ ÙÛÙ
Run Code Online (Sandbox Code Playgroud)
如何使用PHP DOMDocument获取正确的unicode字符.
标题中提到的错误文档说明
如果你的命令不同步; 您现在无法在客户端代码中运行此命令,而是以错误的顺序调用客户端函数.
例如,如果您使用mysql_use_result()并尝试在调用mysql_free_result()之前执行新查询,则会发生这种情况.如果您尝试执行两个返回数据的查询而不在其间调用mysql_use_result()或mysql_store_result(),也会发生这种情况.
从这里:http://dev.mysql.com/doc/refman/5.0/en/commands-out-of-sync.html
但是在First Query中我没有从mysql数据库中获取任何数据,我只是插入.在第二个查询中,我从数据库中获取数据.
这是我的代码
$connection = mysqli_connect("localhost","username","password","tbl_msgs");
if(mysqli_connect_errno($connection))
{
die("Failed to connect to MySQL: " . mysqli_connect_error());
}
$query = "INSERT INTO users (total_comments, total_views)
VALUES ({$total_comments}, {$total_views});";
$query .= "INSERT INTO msgs (notifications) VALUES ({$notifications})";
mysqli_multi_query($connection,$query);
Run Code Online (Sandbox Code Playgroud)
每一件事情都很好.但是当我执行以下查询时它会给出错误
$select_query = "SELECT * FROM msgs WHERE msg_id = {$msg_id}";
$result_set = mysqli_query($connection,$select_query);
if(!$result_set) {
die(mysqli_error($connection));
}
Run Code Online (Sandbox Code Playgroud)
这里给出了错误Commands out of sync; you can't run this command now.我无法理解这种情况
注意:查询中有任何问题,我已经直接向PHPMyAdmin执行了相同的查询,并且工作正常.
我正在动态生成一个字符串.例如,字符串看起来像这样
$string = "this-is-a-test-string-for-example-";
Run Code Online (Sandbox Code Playgroud)
它也可以是这样的
$string = "this-is-a-test-string-for-example";
Run Code Online (Sandbox Code Playgroud)
我想如果"-"在字符串的末尾有一个连字符,它应该被删除.我怎么能在PHP或正则表达式中这样做?
我需要获取所有具有样式属性的标签
$html = '<div style="font-style: italic; text-align: center;
background-color: red;">On The Contrary</div><span
style="font-style: italic; background-color: rgb(244, 249, 255);
font-size: 32px;"><b style="text-align: center;
background-color: rgb(255, 255, 255);">This is USA</b></span>';
$dom = new DOMDocument;
$dom->loadHTML($html);
$xp = new DOMXpath($dom);
foreach ($xp->query('/*[@style]') as $node) {
$style = $node->getAttribute('style');
echo $style;
}
Run Code Online (Sandbox Code Playgroud)
但它没有任何要求。我的代码有什么错误?而且,我也只想获取样式中的CSS PRoperty名称,例如font-size,font-weight,font-family,而不是它们的值。
我想在用户提交的帖子标题的基础上在URL中使用连字符分隔的字符串.假设用户输入帖子的标题如下
$title = "USA is going to deport indians -- Breaking News / News India";
Run Code Online (Sandbox Code Playgroud)
我想将其转换如下
$url = "usa-is-going-to-deport-indians-breaking-news-news-india";
Run Code Online (Sandbox Code Playgroud)
可能还有一些我想要转换的角色.例如'&'到'和'和'#','%',到连字符( - ).其中一种方法是使用php替换功能.但是使用这种方法,我必须多次调用replace函数.这很费时间.还有一个问题是标题字符串中可能有多个连字符( - ),我想将多个连字符( - )转换为一个连字符( - ).
有没有强大而有效的方法来解决这个问题?