导航:首页 > 编程语言 > 经典的php代码

经典的php代码

发布时间:2023-03-12 11:23:16

‘壹’ 最简单 php 代码

<?php

mysql_query("insert into guahao values('".$name."','".$nl."','".$shouji."','".$sname."','".$info."')");
?>

‘贰’ 求个简单的php代码

_tags($string, $replace_with_space = true)
{
if ($replace_with_space) {
return preg_replace('!<[^>]*?>!', ' ', $string);
} else {
return strip_tags($string);
}
}

截取字符函数(匹配各种编码)
function truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false){
if ($length == 0)
return '';

if (is_callable('mb_strlen')) {
if (mb_detect_encoding($string, 'UTF-8, ISO-8859-1') === 'UTF-8') {
// $string has utf-8 encoding
if (mb_strlen($string) > $length) {
$length -= min($length, mb_strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1));
}
if (!$middle) {
return mb_substr($string, 0, $length) . $etc;
} else {
return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, - $length / 2);
}
} else {
return $string;
}
}
}
// $string has no utf-8 encoding
if (strlen($string) > $length) {
$length -= min($length, strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
}
if (!$middle) {
return substr($string, 0, $length) . $etc;
} else {
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
}
} else {
return $string;
}
}

综合就是
$arc=strip_tags($arc);
$arc=truncate($arc,200)

‘叁’ php最经典,最基础的代码,适合入门的

PHP是一种可以嵌入到HTML中的运行在服务器端的脚本语言,所以为了体现PHP的特性我们可以分两种模式来实现PHP代码

1、 PHP嵌入到HTML中,例如index.php

<html>
<head></head>
<body>
<!--因为PHP嵌入到HTML中,所以需要完全区分PHP代码和HTML代码-->
<?php
//输出helloworld
echo'helloworld;
?>
</body>
</html>

2、 PHP独立文件,只有PHP代码,例如index.php

<?php

//输出
echo'helloworld';

//不需要闭合标签

‘肆’ 帮忙些段简单的PHP代码

<?php
$type
=
$_GET["type"];
////下面这个是进入选择的值,根据这个值进入页面
$html
=
"<script>";
$html
.=
"window.location.href='".
$type.".php'";
$html
.=
"</script>";
echo
$html;
//如果你想做别的
switch($type){
case
'qq':
echo
"你进入了QQ,接下来你想做什么可以在这里再做判断";
break;
case
'msn'"
echo
"你进入了MSN,接下来你想做什么可以在这里再做判断";
break;
}
如果还有别的要求,可以接着说,或着给我发求助之类的,我能帮的会帮的!
?>

阅读全文

与经典的php代码相关的资料

热点内容
以后缺程序员吗 浏览:293
jsp源码不能运行 浏览:363
淘客助手源码下载 浏览:733
如何使用app记账报税 浏览:562
python线程捕捉键盘 浏览:25
地推统计图app怎么做 浏览:162
android文件夹不能用了 浏览:857
加密软件的日志 浏览:892
肾病pdf 浏览:230
网站怎么用本地服务器 浏览:120
javadoc导入android 浏览:517
文件扫描成pdf 浏览:696
凉山火灾救援命令 浏览:54
压缩机三相检测 浏览:861
linux怎么安装光盘 浏览:799
宽带服务器无响应是为什么 浏览:226
压缩包内看图 浏览:914
安卓手机如何发现app后台调用情况 浏览:561
程序员简历工作描述 浏览:159
服务器中强制疾跑的指令是什么 浏览:54