插件3:友好的文本

<?php // Plug-in 3: Friendly Text

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$speech = "<h3>Winston Churchill: 'We will never surrender'</h3>I have, myself, full confidence that if all do their duty, if nothing is neglected, and if the best arrangements are made, as they are being made, we shall prove ourselves once again able to defend our Island home, to ride out the storm of war, and to outlive the menace of tyranny, if necessary for years, if necessary alone.<br />   At any rate, that is what we are going to try to do. That is the resolve of His Majesty's Government - every man of them. That is the will of Parliament and the nation.<br />   Even though large tracts of Europe and many old and famous States have fallen or may fall into the grip of the Gestapo and all the odious apparatus of Nazi rule, we shall not flag or fail.<br />   We shall go on to the end, we shall fight in France, we shall fight on the seas and oceans, we shall fight with growing confidence and growing strength in the air, we shall defend our Island, whatever the cost may be, we shall fight on the beaches, we shall fight on the landing grounds, we shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender.";

echo PIPHP_FriendlyText($speech, TRUE);

function PIPHP_FriendlyText($text, $emphasis)
{
   // Plug-in 3: Friendly Text
   //
   // This plug-in takes a string variable containing English
   // text, processes it into a 'friendly' form of speech and
   // returns the modified text. It takes these arguments:
   //
   //    $text:     Text to be modified
   //    $emphasis: If TRUE underlines all modifications

   $misc = array("let us", "let's", "i\.e\.", "for example",
      "e\.g\.", "for example", "cannot", "can't", "can not",
      "can't", "shall not", "shan't", "will not", "won't");
   $nots = array("are", "could", "did", "do", "does", "is",
      "had", "has", "have", "might", "must", "should", "was",
      "were", "would");
   $haves = array("could", "might", "must", "should", "would");
   $who = array("he", "here", "how", "I", "it", "she", "that",
      "there", "they", "we", "who", "what", "when", "where",
      "why", "you");
   $what = array("am", "are", "had", "has", "have", "shall",
      "will", "would");
   $contraction = array("m", "re", "d", "s", "ve", "ll", "ll",
      "d");

   for ($j = 0 ; $j < sizeof($misc) ; $j += 2)
   {
      $from = $misc[$j];
      $to   = $misc[$j+1];
      $text = PIPHP_FT_FN1($from, $to, $text, $emphasis);
   }

   for ($j = 0 ; $j < sizeof($nots) ; ++$j)
   {
      $from = $nots[$j] . " not";
      $to   = $nots[$j] . "n't";
      $text = PIPHP_FT_FN1($from, $to, $text, $emphasis);
   }
   
   for ($j = 0 ; $j < sizeof($haves) ; ++$j)
   {
      $from = $haves[$j] . " have";
      $to   = $haves[$j] . "'ve";
      $text = PIPHP_FT_FN1($from, $to, $text, $emphasis);
   }

   for ($j = 0 ; $j < sizeof($who) ; ++$j)
   {
      for ($k = 0 ; $k < sizeof($what) ; ++$k)
      {
         $from = "$who[$j] $what[$k]";
         $to   = "$who[$j]'$contraction[$k]";
         $text = PIPHP_FT_FN1($from, $to, $text, $emphasis);
      }
   }

   $to = "'s";
   $u1 = $u2 = "";

   if ($emphasis)
   {
      $u1 = "<u>";
      $u2 = "</u>";
   }

   return preg_replace("/([\w]*) is([^\w]+)/", "$u1$1$to$u2$2",
      $text);
}

function PIPHP_FT_FN1($f, $t, $s, $e)
{
   $uf = ucfirst($f);
   $ut = ucfirst($t);
   
   if ($e)
   {
      $t  = "<u>$t</u>";
      $ut = "<u>$ut</u>";
   }
   
   $s   = preg_replace("/([^\w]+)$f([^\w]+)/",  "$1$t$2",  $s);
   return preg_replace("/([^\w]+)$uf([^\w]+)/", "$1$ut$2", $s);
}

?>

1. 插件说明:

 插件3接受一个字符串变量,它代表需要转换的英文文本,需要把它转变为比较有好的格式,返回转换后的英文文本。它需要以下参数:

$text 字符串变量,包含需要修改的文本

$empasis 布尔变量,如果实true,则用下划线表示修改过的内容


springboot100基于Springboot+Vue精准扶贫管理系统-毕业源码案例设计 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值