当前位置: 编程技术>php
本页文章导读:
▪教你如何把一篇文章按要求分段
<?php $a="这是一个小段落.看吧"; $a.="这又是小句!"; $a.="最后一句?"; $a.="这是结果了!"; //其实这是一个长的字句。 $b=split("[\.\!\?]",$a,4); //根本句号,!号,问号等按自己的要求分段 for($index=0;.........
▪全文搜索和替换
<?php exec("/bin/grep -r '$oldword' $rootpath", $results, $errorCode); if ($errorCode){ if ($errorCode == 1){ echo "Possibly no files were found with $oldword in them<BR>\n"; } echo "OS Error: $errorCode<BR>\n"; e.........
▪转换中文日期的PHP程序
本程序将中文日期输出为2001-12-23,并很好解决了“十”的问题,如“十一”和“二十一”中“十”的处理!稍加修改可改为函数。 <? $str="二零○一年十二月二十三日"; echo $str."<p>"; .........
[1]教你如何把一篇文章按要求分段
来源: 互联网 发布时间: 2013-11-30
<?php
$a="这是一个小段落.看吧";
$a.="这又是小句!";
$a.="最后一句?";
$a.="这是结果了!";
//其实这是一个长的字句。
$b=split("[\.\!\?]",$a,4);
//根本句号,!号,问号等按自己的要求分段
for($index=0;$index<count($b);$index++)
{
print "$index.$b[$index]<br>";
}
//在循环中读出数组。
?>
$a="这是一个小段落.看吧";
$a.="这又是小句!";
$a.="最后一句?";
$a.="这是结果了!";
//其实这是一个长的字句。
$b=split("[\.\!\?]",$a,4);
//根本句号,!号,问号等按自己的要求分段
for($index=0;$index<count($b);$index++)
{
print "$index.$b[$index]<br>";
}
//在循环中读出数组。
?>
[2]全文搜索和替换
来源: 互联网 发布时间: 2013-11-30
<?php
exec("/bin/grep -r '$oldword' $rootpath", $results, $errorCode);
if ($errorCode){
if ($errorCode == 1){
echo "Possibly no files were found with $oldword in them<BR>\n";
}
echo "OS Error: $errorCode<BR>\n";
echo "Check 'man errno' and count down<BR>\n";
echo "Usually paths/permissions<BR>\n";
}
while (list(,$path) = each($results)){
$parts = explode(':', $path);
$path = $parts[0];
$fp = fopen($path, 'r') or print("Cannot read $path<BR>\n");
if ($fp){
$data = fread($fp, filesize($path));
fclose($fp);
$newdata = str_replace($oldword, $newword, $data);
$fp = fopen($path, 'w') or print("Cannot write $path<BR>\n");
if ($fp){
fwrite($fp, $newdata);
fclose($fp);
echo $path, "<BR>\n";
}
}
}
?>
Example
http://yourserver.com/globalreplace.php?oldword=test&newword=text&rootpath=/path/to/dir
exec("/bin/grep -r '$oldword' $rootpath", $results, $errorCode);
if ($errorCode){
if ($errorCode == 1){
echo "Possibly no files were found with $oldword in them<BR>\n";
}
echo "OS Error: $errorCode<BR>\n";
echo "Check 'man errno' and count down<BR>\n";
echo "Usually paths/permissions<BR>\n";
}
while (list(,$path) = each($results)){
$parts = explode(':', $path);
$path = $parts[0];
$fp = fopen($path, 'r') or print("Cannot read $path<BR>\n");
if ($fp){
$data = fread($fp, filesize($path));
fclose($fp);
$newdata = str_replace($oldword, $newword, $data);
$fp = fopen($path, 'w') or print("Cannot write $path<BR>\n");
if ($fp){
fwrite($fp, $newdata);
fclose($fp);
echo $path, "<BR>\n";
}
}
}
?>
Example
http://yourserver.com/globalreplace.php?oldword=test&newword=text&rootpath=/path/to/dir
[3]转换中文日期的PHP程序
来源: 互联网 发布时间: 2013-11-30
本程序将中文日期输出为2001-12-23,并很好解决了“十”的问题,如“十一”和“二十一”中“十”的处理!稍加修改可改为函数。
<?
$str="二零○一年十二月二十三日";
echo $str."<p>";
$flag=0;
$cn=array("一","二","三","四","五","六","七","八","九","十","零","○");
$num=array("1","2","3","4","5","6","7","8","9","","0","0");
$len=strlen($str);
for ($i=0;$i<$len;$i+=2)
{
$array_str[$i]=substr($str,$i,2);
$cout=0;
while($cout<count($cn))
{
if ($array_str[$i]==$cn[$cout])
{
if ($flag==1)
echo "-";
if (($array_str[$i]=="十") and ($flag==1))
{
$temp[$cout]="1";
echo $temp[$cout];
$flag=2;break;
}
$temp[$cout]=$num[$cout];
echo $temp[$cout];
$flag=2;
break;
}
else
{
if (count($cn)==$cout+1)
$flag=1;
}
$cout++;
}
}
?>
<?
$str="二零○一年十二月二十三日";
echo $str."<p>";
$flag=0;
$cn=array("一","二","三","四","五","六","七","八","九","十","零","○");
$num=array("1","2","3","4","5","6","7","8","9","","0","0");
$len=strlen($str);
for ($i=0;$i<$len;$i+=2)
{
$array_str[$i]=substr($str,$i,2);
$cout=0;
while($cout<count($cn))
{
if ($array_str[$i]==$cn[$cout])
{
if ($flag==1)
echo "-";
if (($array_str[$i]=="十") and ($flag==1))
{
$temp[$cout]="1";
echo $temp[$cout];
$flag=2;break;
}
$temp[$cout]=$num[$cout];
echo $temp[$cout];
$flag=2;
break;
}
else
{
if (count($cn)==$cout+1)
$flag=1;
}
$cout++;
}
}
?>
最新技术文章: