MYSQL数据表的输出

本文章来给php初学者介绍一个不错的php mysql入门实例,我们连接数据库并实现显示出数据库中的记录实例,各位朋友可参考。

连接到一个 MySQL 数据库

在您能够访问并处理数据库中的数据之前,您必须创建到达数据库的连接。

在 PHP 中,这个任务通过 mysql_connect() 函数完成。

语法

mysql_connect(servername,username,password); 继续阅读

PHP null常量和null字节的区别

在学习isset()时,看到了这句话:“如果已经使用 unset() 释放了一个变量之后,它将不再是 isset()。若使用 isset() 测试一个被设置成 NULL 的变量,将返回 FALSE。同时要注意的是一个 NULL 字节(”\0″)并不等同于 PHP 的 NULL 常数”。那么问题来了,什么是NULL字节(“\0”)? 它和NULL常数有什么区别呢??

  NULL 字节是变量为空 $t = ”; 变量有值,不过是空,isset()是TRUE
  NULL 常数是$t=null; 变量没有值,没有分配存储空间,isset()是FALSE
测试一下:

$a = '';
    var_dump(isset($a));
    echo "</br>";
    unset($a);
    var_dump($a);
    echo "</br>";
    $b = null;
    var_dump(isset($b));

运行结果如下:
boolean true
null
boolean false

xmlrpc.php防攻击

.htaccess下加入

# protect xmlrpc
<Files xmlrpc.php>
Order Deny,Allow
Deny from all
</Files>

或模板文件functions.php添加

add_filter('xmlrpc_enabled','__return_false');

location =/xmlrpc.php{
deny all;
}
Control XML-RPC publishing

访问域名/xmlrpc.php由原来的
XML-RPC server accepts POST requests only.
变成403错误
Forbidden
You don’t have permission to access /xmlrpc.php on this server.
kangle 服务器提示
Something error:
403 Forbidden
denied by request access control
ngnix提示:
403 Forbidden
You don’t have permission to access the URL on this server. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!

URL: http://www.xxx.com/xmlrpc.php
Server: wanlifu.wang
Date: 2019/08/02 23:09:54

wp_pagenavi

functions.php
查找

?></h3>

替换

<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>

<?php
wp_pagenavi(); ?>

content.php移除

                <div class="featured-post">
			<?php _e( 'Featured post', 'twentytwelve' ); ?>
		</div>

include有返回值,而require没有。include和require的差别

wp-blog-header.php

/**
 * Loads the WordPress environment and template.
 *加载WordPress环境和模板
 * @package WordPress
 */

if ( !isset($wp_did_header) ) {

	$wp_did_header = true;

	// Load the WordPress library.
	require_once( dirname(__FILE__) . '/wp-load.php' );

	// Set up the WordPress query.
	wp();

	// Load the theme template.
	require_once( ABSPATH . WPINC . '/template-loader.php' );

}

.require 的使用方法如 require(“MyRequireFile.php”); 。这个函数通常放在 PHP 程序的最前面,PHP 程序在执行前,就会先读入 require 所指定引入的文件,使它变成 PHP 程序网页的一部份。常用的函数,亦可以这个方法将它引入网页中。

include 使用方法如 include(“MyIncludeFile.php”); 。这个函数一般是放在流程控制的处理部分中。PHP 程序网页在读到 include 的文件时,才将它读进来。这种方式,可以把程序执行时的流程简单化。

他们两个的用途是完全一样的,不一定非得哪个放在最前面哪个放在中间。他们最根本的区别在于错误处理的方式不一样。

require一个文件存在错误的话,那么程序就会中断执行了,并显示致命错误
include一个文件存在错误的话,那么程序不会中端,而是继续执行,并显示一个警告错误。

以下为补充:

1. include有返回值,而require没有。

2. include()包括并运行指定文件 在处理失败时include() 产生一个警告,被导入的程序代码都会被执行,而且这些程序在执行的时候会拥有和源文件中呼叫到include()语句的位置相同的变量范围。你可以导入同一个服务器中的静态页面。

include有返回值,而require没有。include和require的差别

include有返回值,而require没有。include和require的差别

3. include_once()的作用和include()是几乎相同的
唯一的差别在于include_once()会先检查要导入的档案是不是已经在该程序中的其它地方被导入过了,如果有的话就不会再次重复导入(这项功能有时候是很重要的,比方说要导入的里面宣告了一些你自行定义好的函数,那么如果在同一个程序重复导入这个文件,在第二次导入的时候便会发生错误讯息,因为PHP不允许相同名称的函数被重复宣告第二次)。

4. require()会将目标文件的内容读入,并且把自己本身代换成这些读入的内容 在处理失败时require() 则导致一个致命错。 继续阅读

PHP的 “魔术常量”__FILE__使用说明

index.php
wordpress应用程序的前台,这个文件不做任何事情,但加载wp-blog-header.php,这个文件起作用并告诉wordpress加载主题。

/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

在网上查了一下。总结了以下规律。
dirname(__FILE___) 函数返回的是脚本所在在的路径。
比如文件 b.php 包含如下内容:

< ?php $basedir = dirname(__FILE__); ?>
PHP的 "魔术常量"__FILE__使用说明

PHP的 “魔术常量”__FILE__使用说明

如果b.php被其他目录里的a.php文件require 或者 include 去引用的话。
变量$basedir 的内容还是b.php所在的那个文件夹的路径。
而不是变成a.php文件所在的目录。
dirname(__FILE__) 一般会返回文件所的当前目录到系统根目录的一个目录结构。
不会返回当前的文件名称。
dirname(__FILE__) 也可能返回一个 . (当前目录)
[原因是 b.php 文件在 http.conf 或者 PHP 配置开发环境的默认WEB目录下.
比如 WEB_ROOT 为: “C:/root/www/”.]
b.php文件路径为: “C:/root/www/b.php”.
继续阅读

CSS中line-height与height的区别

文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字

如果我们定义.test {line-height:20px;},那么这个元素的实际高度将取决于其中内容的多少,假如文字部分在浏览器里面显示为一行,那么这个div的实际高度就是20px,如果文字显示为两行,那么div的实际高度就是40px,而且文字的行高是20px的;

如果我们定义.test{height:40px},那么这个元素的实际高度一般并不会因为内容的多少而发生改变,如果文字显示为一行,那么这个div的高度仍然是40px,如果显示为2行,但是文字的行高不够20px,这个div的高度也不会因为文字内容的高度小于height而发生改变。不过如果文字内容的高度大于40px了,一般来说这个div的高度还是会相应增加的。

CSS中line-height与height的区别

CSS中line-height与height的区别

带随机功能的文字滚动广告效果JS代码

var marqueeContent=new Array();   //滚动主题
                  	
marqueeContent[0]='<a href="http://www.lifu.in/hongjiu" target="_blank">+ 点击我!网上买正品法国波尔多干红葡萄酒</a>';
marqueeContent[1]='<a href="http://www.13rich.com/chashaobao.html" target="_blank">+ 洛天依:有人吃的多有人吃的少,有人吃饱了又了还饿着?</a>';
marqueeContent[2]='<a href="http://www.lifu.in/nanjing-techan" target="_blank">+ 点击我!南京特产网上卖!盐水鸭、泡椒凤爪、云锦框画、夫子庙美食</a>';
marqueeContent[3]='<a href="http://www.oosky.net/how-the-universe-works.html" target="_blank">+ 恒星世界在暴力中诞生,也在暴力中消亡!《了解宇宙如何运行》</a>';
marqueeContent[4]='<a href="http://www.lifu.in/sijin" target="_blank">+ 点击我!祥义号、宝石蝶等真丝睡衣、真丝丝巾等品牌网上卖</a>';
marqueeContent[5]='<a href="http://www.lifu.in/dian/1.html" target="_blank">+ 点击我!飞碟说、《娱乐猛回头》等100个最搞笑系列视频</a>';
marqueeContent[6]='<a href="http://www.lifu.in/quban" target="_blank">+ 女人必看!瓷肌、芦荟胶去黄补水保湿淡斑的好办法</a>';
marqueeContent[7]='<a href="http://www.5sing.info/yihonglian.html" target="_blank">+ 点击我!虚拟萝莉歌手的古风音乐《忆红莲》欣赏</a>';

var marqueeInterval=new Array();  //定义一些常用而且要经常用到的变量
var marqueeId=0;
var marqueeDelay=5000;
var marqueeHeight=60;
function initMarquee() {
 var number=Math.floor(Math.random()*8);
 marqueeId=number;
 var str=marqueeContent[marqueeId];
 document.write('<div id=marqueeBox style="overflow:hidden;height:'+marqueeHeight+'px" onmouseover="clearInterval(marqueeInterval[0])" onmouseout="marqueeInterval[0]=setInterval(\'startMarquee()\',marqueeDelay)"><div>'+str+'</div></div>');
 marqueeId++;
 if(marqueeId>=marqueeContent.length) marqueeId=0;
 marqueeInterval[0]=setInterval("startMarquee()",marqueeDelay);
 }
function startMarquee() {
 var str=marqueeContent[marqueeId];
  marqueeId++;
 if(marqueeId>=marqueeContent.length) marqueeId=0;
 if(marqueeBox.childNodes.length==1) {
  var nextLine=document.createElement('DIV');
  nextLine.innerHTML=str;
  marqueeBox.appendChild(nextLine);
  }
 else {
  marqueeBox.childNodes[0].innerHTML=str;
  marqueeBox.appendChild(marqueeBox.childNodes[0]);
  marqueeBox.scrollTop=0;
  }
 clearInterval(marqueeInterval[1]);
 marqueeInterval[1]=setInterval("scrollMarquee()",10);
 }
function scrollMarquee() {
 marqueeBox.scrollTop++;
 if(marqueeBox.scrollTop%marqueeHeight==marqueeHeight){
  clearInterval(marqueeInterval[1]);
  }
 }
initMarquee();

对以上代码进行改编可以变成三行滚动的代码。 继续阅读