PHP学习笔记——字符串

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>joker</title>
  </head>
  <body>
  <?php
  $greeting = "good morning citizen";
  $farewell = substr_replace($greeting,"bye",5,7);
  echo $farewell;
  echo "<br />";
  $farewell = substr_replace($farewll, "kind ",8,0);
  echo $farewell;
  echo "<br />";
  echo str_repeat('_.-.',40);
  $string = str_pad('Fred Flinststone',30,'.');
  echo "{$string}\n";
  echo "<br />";
  $input = 'Fred,25,Wilma';
  $filed = explode(',',$input);
  echo $filed;
  $string = "Fred,Flinstone,35,Wlima";
  $token = strtok($string,",");
  while ($token !== false) {
      echo("{$token}<br />");
      $token = strtok(",");
  }
  $string = "Fred\tFlintstone (35)";
  $n = sscanf($string,"%s\t%s (%d)",$first,$last,$age);
  echo "{$n},{$first},{$age}<br />";
  $pos = strpos($string,"35");
  if($pos === false){
    // 没有找到
  }
  else {
    // 找到了
  }
  $record = "Fred,Flintstone,35,Wilma";
  $pos = strrpos($record,",");
  echo ("$pos");
  echo "<br />";
  preg_match("/c[^aeiou]","Reboot chthon"); //返回 True
  preg_match("/(<.*>)/","do <b>not</b> press the button",$match);
  echo "$match[1]"; // $match[1]值为<b>not</b>
  preg_match("/(<.*?>)/","do <br>not</b> press the button",$match);
  echo "$match[1]";// $match[1]值为<br>
  preg_match("/(?:ello)(.*)/","jello biafra yummy ",$match);
  echo "$match[1]<br />";
  $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x','y','z'));
  print_r ($a);
  ?>
  </body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值