How to use it To transform any text (including text with HTML) using this code, call the main function in the following way: ```php $oldtext = "Let us go for a picnic. I hope it will not rain."; $newtext = FriendlyText($oldtext, TRUE); ``` The first parameter holds the string to be modified. This will not be changed. Instead, a new string containing the transformed text will be returned by the function. The second parameter can be either FALSE or TRUE, which will cause all changes to be underlined. This can be useful for debugging purposes. In this example, the value of $newtext becomes “Let’s go for a picnic. I hope it won’t rain. If this post has helped you in any way, sign up to the website and leave a hello here in the comments so that we know that the content interests you and that we can bring you more and better quality content."> How to use it To transform any text (including text with HTML) using this code, call the main function in the following way: ```php $oldtext = "Let us go for a picnic. I hope it will not rain."; $newtext = FriendlyText($oldtext, TRUE); ``` The first parameter holds the string to be modified. This will not be changed. Instead, a new string containing the transformed text will be returned by the function. The second parameter can be either FALSE or TRUE, which will cause all changes to be underlined. This can be useful for debugging purposes. In this example, the value of $newtext becomes “Let’s go for a picnic. I hope it won’t rain. If this post has helped you in any way, sign up to the website and leave a hello here in the comments so that we know that the content interests you and that we can bring you more and better quality content."> Friendly text with php

Friendly text with php

Sometimes when you have text to post on a web site, it can be quite dry and unexciting. Although there’s not much you can do about that (apart from completely rewriting it), at least you can make it read better by converting it into as friendly a form as possible by making it flow better by using contractions. For example, replacing you have with you’ve or it is with it’s is easier to read and more like the way we speak in everyday life, and this code takes that concept to the extreme. ##
The function ```php function FriendlyText($text, $emphasis){ $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"); $contractions = 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 = FT_FN1($from, $to, $text, $emphasis); } for($j = 0; $j < sizeof($nots); ++$j){ $from = $nots[$j] . "not"; $to = $nots[$j] . "n't"; $text = FT_FN1($from, $to, $text, $emphasis); } for($j = 0; $j < sizeof($haves); ++$j){ $from = $haves[$j] . " have"; $to = $haves . "'ve"; $text = 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] '$contactions[$k]"; $text = FT_FN1($from, $to, $text, $emphasis); } } $to = "'s"; $u1 = $u2 = ""; if($emphasis){ $u1 = ""; $u2 = ""; } return preg_replace("/([\w]*) is([^\w]+)/", "$u1$1$to$u2$2", $text); } function FT_FN1($f, $t, $s, $e){ $uf = ucfirst($f); $ut = ucfirst($t); if($e){ $t = "$t"; $ut = "$ut"; } $s = preg_replace("/([^\w]+)$f([^\w]+)/", "$1$t$2", $s); return preg_replace("/([^\w]+)$uf([^\w]+)/", "$1$ut$2", $s) } ``` ##
How to use it To transform any text (including text with HTML) using this code, call the main function in the following way: ```php $oldtext = "Let us go for a picnic. I hope it will not rain."; $newtext = FriendlyText($oldtext, TRUE); ``` The first parameter holds the string to be modified. This will not be changed. Instead, a new string containing the transformed text will be returned by the function. The second parameter can be either FALSE or TRUE, which will cause all changes to be underlined. This can be useful for debugging purposes. In this example, the value of $newtext becomes “Let’s go for a picnic. I hope it won’t rain. If this post has helped you in any way, sign up to the website and leave a hello here in the comments so that we know that the content interests you and that we can bring you more and better quality content.

All comments