PHP学习入门

PHP简单学习入门

简单输出

PHP有两种简单输出方式{
1.echo
2.print

echo"hello world<br>";
print 'I would like a bowl of soup';
print 'chicken ';
print '06520 ';
print '"I am eating dinner,"he growled <br>';
print 'we\'ll each have a bowl of soup.<br>';//斜杆加引号输出引号
print 'use a \\ to escape in a string';//两个斜杆化为一个输出

编辑Herr文档

print <<<HTMLBLOCK
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>dinner</h1>
    <ul>
<li>Beef Chow-Fun</li>
<li>Sauteed pea shoots</li>
<li>Soy Sauce Noodles</li>
</ul>
</body>
</html>
HTMLBLOCK;//打印Herr文档

表单字符串处理

//获取表单的值
$str=trim($_POST['zipcode']);
//获取字符串长度
$len=strlen($str);
if($len!=5){
    print'please enter a zip code is 5 characters long .';
}
if($str=='hello'){
    print $str.'<br>';//.代表字符串连接
    print 'welcome to china'.'<br>';
}
//不区分大小写的比较
if(strcasecmp($str,'hello')==0){
    print $str.'<br>';//.代表字符串连接
    print 'welcome to china';
}

一些简单的转化函数

$price=5;
$tax=0.075;
//输出格式为2个小数
printf('the dish costs $%.2f<br>',$price*(1+$tax));
//补0输出
$str='6520';
$month=2;
$day=6;
$year=2007;
printf('zip is %05d and the date is %02d %02d %d<br>',$str,$month,$day,$year);
$min=-40;$max=40;
printf("the computer can operate between %d and %d degrees celsius.<br>",$min,$max);
//改变大小写函数
print strtolower('BEEF DISH DUCK<br>');
print strtoupper('bEEF dISH duCK<br>');
//首字母大写
print ucwords(strtolower('HELLO WORLD')).'<br>';
//子串
$str='hello jun ,i am a little boy, i want to play with you. thank you<br>';
print $str;
print substr($str,0,10);//从0开始提取10个字节
print '...<br>';
$card='4000-1234-5678-9101';
print 'card: xx';
print substr($card,-4,4);//从后往前提取
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值