<!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>
PHP学习笔记——字符串
最新推荐文章于 2024-09-28 17:54:20 发布