×

最简单的php代码示例 代码

最简单的php代码示例(简单PHP代码)

admin admin 发表于2023-01-31 23:34:56 浏览75 评论0

抢沙发发表评论

本文目录

简单PHP代码

$_env 是环境变量,通过环境方式传递给当前脚本的变量的数组。
$_ENV[’defaultapp’] = array(’portal.php’ =》 ’portal’, ’forum.php’ =》 ’forum’, ’group.php’ =》 ’group’, ’home.php’ =》 ’home’);
是赋值 , 你可以用 var_dump($_env[’defaultapp’]) 看赋值结果。
--------------------------------------------------------------------
$_ENV[’hostarr’] = explode(’.’, $_SERVER[’HTTP_HOST’]);
环境变量 用.分隔 主域名(你可以 echo $_server[’HTTP_HOST’]里面有什么)
----------------------------------------------------------------
$url = $domainroot.’forum.php?mod=group&fid=’.$domain[’id’].’&page=1’;
构造一个URL 直白点 结果就是: www.some.com/forum.php?mod=1&fid=1&page=1
----------------------------------------
$url = empty($_ENV[’domain’][’app’][’default’]) ? (!empty($_ENV[’domain’][’defaultindex’]) ? $_ENV[’domain’][’defaultindex’] : ’forum.php’) : ’

看看我的简单php代码

fising的方法是正解:
使用《?php ... ?》这样的形式,更通用,可移植性好;《? ?》只有在服务器开启短标记的情况下才能使用。
PHP3可以直接调用传过来的参数,但从PHP4开始,接收GET方法传过来的值要用$_GET。
上面的代码应该写作:

《table width=“《?php echo $_GET[’w’]; ?》“ border=“《?PHP echo $_GET[’b’]; ?》“ align=center》
《tr》
《td align=center》
欢迎来到《? echo $_GET[’name’]; ?》的网页
《/td》
《/tr》
《/table》
楼主的代码可能是从PHP3教程中抄来的,在PHP3中应该是可行的,但PHP3早已过时,现在恐怕再也找不到支持PHP3的服务器了,应该使用$_GET。
hansuper88显然是没有看清楚题目,变量是通过链接URL传递的,而不是由程序自己赋值的。

求很简单的PHP代码

《?php
$folder=“C:\wamp\www\d“;
$fp=opendir($folder);
while(false!=$file=readdir($fp)){
    if($file!=’.’ &&$file!=’..’){
        $file=“$folder/$file“;
        $arr_file=$file;
    }
}
if(is_array($arr_file)){
while(list($key,$value)=each($arr_file)){
echo $value;
        $key=file_get_contents($value);
$_patten = ’/(1234567)/’;
if (preg_match($_patten,$key)) {
$a= preg_replace($_patten,“7654321“,$key);
file_put_contents($value, $a);
    }
    }
}
closedir($fp);
?》

代码就敲到到这了,感觉有点头痛,正则替换的7654321,你可以定义strrev($1);

php简单smarty入门程序实例

本文实例讲述了php简单smarty入门程序。分享给大家供大家参考。具体如下:
首先要有3个文件夹configs、templates、templates_c,在configs文件夹中有一个配置文件:test.conf,代码:
title
=
Welcome
to
Smarty!
cutoff_size
=
40
[setup]
bold
=
true
templates中有模板文件:test.htm:
《html》
《head》
《title》Smarty
Test《/title》
《/head》
《body》
《H1》Hello,
{$Name}《/H1》
《/body》
《/html》
php文件代码:
《?php
require
’libs/Smarty.class.php’;
//包含Smarty类库文件
$smarty
=
new
Smarty;
//创建一个新的Smarty对象
$smarty-》assign(“Name“,“Simon“);
//对模版中的变量赋值
$smarty-》display(’test.htm’);
//显示页面
?》
运行后显示的页面代码:
《html》
《head》
《title》Smarty
Test《/title》
《/head》
《body》
《H1》Hello,
Simon《/H1》
《/body》
《/html》
运行之后,还在templates_c文件夹中生成一个php文件:
《?php
/*
Smarty
version
2.6.22,
created
on
2009-03-19
13:20:00
compiled
from
test.htm
*/
?》
《html》
《head》
《title》Smarty
Test《/title》
《/head》
《body》
《H1》Hello,
《?php
echo
$this-》_tpl_vars[’Name’];
?》
《/H1》
《/body》
《/html》
这个文件就是浏览所显示出来的效果。
希望本文所述对大家的php程序设计有所帮助。

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

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

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

《html》
《head》《/head》
《body》
    《!--因为PHP嵌入到HTML中,所以需要完全区分PHP代码和HTML代码--》
    《?php
        //输出hello world
        echo ’hello world;
    ?》
《/body》
《/html》

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

《?php
    //输出
    echo ’hello world’;
    
    //不需要闭合标签

求写个比较简单的php登陆页面代码

index.php 录入页代码《form id=“form1“ name=“form1“ method=“post“ action=“login.php“》
《table width=“400“ border=“0“ align=“center“ cellpadding=“1“ cellspacing=“1“ class=“tableborder“》
《tr》
《td》《div align=“right“》用户名:《/div》《/td》
《td width=“244“》
《input type=“text“ name=“User_name“ id=“User_name“ /》 《/td》
《/tr》
《tr》
《td》《div align=“right“》密 码:《/div》《/td》
《td》《input type=“Password“ name=“User_Password“ id=“User_Password“ /》《/td》
《/tr》
《tr》
《td》
《div align=“right“》
《input type=“submit“ name=“button“ id=“button“ value=“提交“ /》
《/div》《/td》
《td》《input type=“reset“ name=“button2“ id=“button2“ value=“重置“ /》《/td》
《/tr》
《/table》
《/form》 login.php提交页代码《?
error_reporting(0);
$mysql_servername = “127.0.0.1“;
$mysql_username = “root“;
$mysql_password =“123456“;
$mysql_database =“first“;
mysql_connect($mysql_servername , $mysql_username , $mysql_password);
mysql_select_db($mysql_database);
$U_name=$_POST[’user_name’];
$U_passowrd=$_POST[’user_password’];
if ($U_name && $U_passowrd){
$sql = “SELECT * FROM admin WHERE U_name = ’$U_name’ and U_password=’$U_passowrd’“;
$res = mysql_query($sql);
$rows=mysql_num_rows($res);
if($rows){
header(“location=’c.php’“);
exit;
}
echo “《script language=javascript》alert(’用户名密码错误’);history.back();《/script》“;
}else {
echo “《script language=javascript》alert(’用户名密码不能为空’);history.back();《/script》“;
}
?》

php导出word文档与excel电子表格的简单示例代码

本篇文章主要是对php导出word文档与excel电子表格的简单示例代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助
生成word的代码:
代码如下:
header(“Content-type:
application/octet-stream“);
header(“Accept-Ranges:
bytes“);
header(’Content-type:
application/doc’);
header(’Content-Disposition:
attachment;
filename=“测试.doc“’);

生成excel的代码

代码如下:
Header(“Content-type:
application/octet-stream“);
Header(“Accept-Ranges:
bytes“);
Header(“Content-type:application/vnd.ms-excel“);
Header(“Content-Disposition:attachment;filename=“测试.xls“’);

但是导的过程中也会遇到很多问题,比如说导出excel,某列导出的是身份证号的话,打开excel文件以后会发现,身份证号自动采用科学计数法,无论如何修改该列属性,都无法实现自己的要求。网上有人说,先把该列属性改为文本以后,再输入就没有问题,实际操作excel确实如此,但是,php程序导出就无法做到了。也有人说,在身份证号前加单引号,试过也不行,最后在导出的身份证号数据前加空格问题解决,空格是html代码的空格.问题解决。

求个简单的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
mysql_query(“insert into guahao values(’“.$name.“’,’“.$nl.“’,’“.$shouji.“’,’“.$sname.“’,’“.$info.“’)“);
?》

求一段简单php代码

《?php
echo“开头“;
for($i=1;$i《5;$i++)
{
$b = ’class’.$i;
echo $b;
}
echo“结尾“;
?》
或者
《?php
for($i=1;$i《5;$i++)
{
if($i==1) echo“开头“;
$b = ’class’.$i;
echo $b;
if($i==1) echo“结尾“;
}
?》
//这不很简单吗