Not sure about #1 as im a newbie myself. But this script will strip away all numbers from a text string (i hope there is a simpler way to do this, atleast when it comes to removing letters):
<?php
$streng="hello 123 my name 123 is crowly";
echo "Input: ".$streng."<br>";
$ra=array(0,1,2,3,4,5,6,7,8,9);
// str_ireplace() is case insensitive, str_replace() is case sensitive
$streng=str_ireplace($ra,"",$streng);
echo "Output: ".$streng;
?>
It will look like this:
Input: hello 123 my name 123 is crowly
Output: hello my name is crowly
For number 2 and 3 i think the approach will be about the same, hope these simple scripts might point you in the right direction 🙂
<?php
$streng="hello my name is crowly";
echo "Input: ".$streng."<br>";
//counts the number of word in the string
$n=str_word_count($streng);
//make the string into an array
$exstr=(explode(" ",$streng));
$i=0;
while ($i!==$n)
{
//converts the first char of each field to upper case
$exstr[$i]=ucfirst($exstr[$i]);
// when $i == number of words, exit loop
$i++;
}
//turn the array back into a string
$streng=implode(" ",$exstr);
// add a . to the end
$streng=$streng.".";
echo "Output: ".$streng;
?>
Edit: Or one can do it the easy way, as i just found out ...
<?php
$streng="hello my name is crowly";
echo "Input: ".$streng."<br>";
$streng=ucwords($streng);
echo "Output: ".$streng;
?>
Both scripts will look like this:
Input: hello my name is crowly
Output: Hello My Name Is Crowly.
<?php
$streng="hello. my name. is crowly";
echo "Input: ".$streng."<br>";
// count the number of dots in the string
$n=substr_count($streng,".");
//make the string into an array
$exstr=(explode(".",$streng));
$i=1;
while ($i!==$n+1)
{
//converts the first char of each field after the first to upper case
//ltrim() removes any spaces at the beginning (left) of each field
$exstr[$i]=ucfirst(ltrim($exstr[$i]));
// when $i == number of words, exit loop
$i++;
}
//turn the array back into a string, the removed spaces are added back here with ". "
$streng=implode(". ",$exstr);
// add a . to the end
$streng=$streng.".";
echo "Output: ".$streng;
?>
This scripts outputs this:
Input: hello. my name. is crowly
Output: hello. My name. Is crowly.