PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有: (int)、(integer):转换成整形 (float)、(double)、(real):转换成浮点型 (string):转换成字符串 (bool)、(boolean):转换成布尔类型 (array):转换成数组 (object):转换成对象 PHP数据类型有三种转换方式: 在要转换的变量之前加上用括号括起来的目标类型 使用3个具体类型的转换函数,intval()、floatval()、strval() 使用通用类型转换函数settype(mixed var,string type) 第一种转换方式: (int) (bool) (float) (string) (array) (object) <?php $num1=3.14; $num2=(int)$num1; var_dump($num1); //输出float(3.14) var_dump($num2); //输出int(3) ?> 第二种转换方式: intval() floatval() strval() <?php $str=”123.9abc”; $int=intval($str); //转换后数值:123 $float=floatval($str); //转换后数值:123.9 $str=strval($float); //转换后字符串:”123.9″ ?> 第三种转换方式: settype(); <?php $num4=12.8; $flg=settype($num4,”int”); var_dump($flg); //输出bool(true) var_dump($num4); //输出int(12) ?> from:http://banu.blog.163.com/blog/static/231464820101122114438674/
UTF8 中文截取 其中对字符串预先 __() 处理,可以从 qtranslate 中取出当前语言部分然后进行截取。 function utf8Substr($str, $from, $len) { if ($len == 0){ return __($str); }else{ return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'. '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', '$1',__($str)); } } //use utf8Substr($recent["post_title"],0,14); function utf8_trim($str) { $len = strlen($str); for ($i=strlen($str)-1; $i>=0; $i-=1){ $hex .= ' '.ord($str[$i]); $ch = ord($str[$i]); if (($ch & 128)==0) return(substr($str,0,$i)); if (($ch & [...]
This piece of code should do it for you. Place this code in your theme’s functions.php file. You can add customizations to the custom_password_form() function – just don’t use print or echo – the function must return a value. <?php add_filter( 'the_password_form', 'custom_password_form' ); function custom_password_form() { global $post; $label = 'pwbox-'.( empty( $post->ID ) [...]
在用Qtranslate 做多语言网站的时候,常常发现自己写的代码输出的时候把中英文连带语言区分的容器 “” 也移动输出了。 解决方法就是在输出是用 function __() 或 _e() 进行处理即可: 例如: <?php $args = array( 'numberposts' => '10','category' => 1, 'post_status' => 'publish' ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.__($recent["post_title"]).'" >' . __($recent["post_title"]).'</a><span>'.$recent["post_date"].'</span></li> '; } ?>
Changes double line-breaks in the text into HTML paragraphs (<p>…</p>). 把文章里的 2次换行 格式化成 html 段落(<p>…</p>). $foo (string) (required) The text to be formatted. 需要格式化的文章。 Default: None $br (boolean or integer) (optional) Preserve line breaks. When set to true, any line breaks remaining after paragraph conversion are converted to HTML . Line breaks within script and [...]
Advanced Custom Fields for wordpress 是一个不错的插件,但是api 里只有 get fields,却没有get labels,对此,作者认为没有必要(作者的论坛上表示的)。一般情况是真的没必要。但是有会更好! 在配合 WPML 做多语言网站的时候就大有用处了,可以设置不同的 Field Label 用相同的 Field Name,这样就可以实现切换语言的时候自动切换 Field Label,而用相同的 get field 获取不同 label 下面的值。 吧下面的代码放进header.php 或这 function.php function get_acf_labels($name = null, $post_id) { global $wpdb; //SELECT name, label FROM wp_acf_fields as waf left jolin wp_acf_values as wav on wav.field_id = waf.id where [...]
Post Formats 是wordpress 3.1 引入的新更能,直观的,你可以在写文章页面看到 然后再single.php模板文件里可以看到这样一行代码 来指定这篇文章使用哪个模板文件。 在/wp-includes/post.php 里面,可以看到系统预设的几个格式。 但是仍然需要在模板文件里注册主持。 方法是在模板的 function.php 里加上 add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); 或者你觉得不需要这么多,可以删除一些。但是必须和上面预设的单词一样,程序会比较模板注册的和默认的格式,只有匹配的才主持。 感觉有些不太只能,但是想想有7中格式了,也差不多了。
去掉那些header里不重要的元素,写在 WP_HEAD() 的前面: 有时候 plugin 注册进来的 action, 可以去插件里面找到 action 的名字,一般会像这样 有时和你不能有选择的去除这些,或许就直接全部去除吧,然后再根据自己的意愿手动加载管理:
// 更多报头 $headers .= "From: 姚迎迎 <admin@yaoyingying.com>". "\r\n" ."CC: yao3060@gmail.com, yao3060@hotmail.com"; 突然发现 php mail 函数 抄送的时候, header 里用 单引号 (‘) 竟然会有错误,一定要用双引号。。。。。。 NND 这一直是一个误解,其实 \r\n 必须使用双引号(”")
How To Use PHP to Force a File Download http://webdesign.about.com/od/php/ht/force_download.htm PHP allows you to change the HTTP headers of files that you’re writing, so that you can force a file to be downloaded that normally the browser would load in the same window. This is perfect for files like PDFs, document files, images, and video [...]

Posted on 18, 十











