Wednesday, July 6, 2011

7/6/2011


<?php
//let's find the number of o's in our string.
$counter = substr_count("Hello World!", "o");
echo "There are " . $counter . " instance(s) of \"o\" in Hello World!.";
?>



<?php
$theclientstext = "Hello, how are you today? I am fine!";

if (strlen($theclientstext) >= 30){
echo substr($theclientstext,0,29);
} else {
echo $theclientstext;
}


$url = "www.apress.com";
$domain = strstr($url, ".");
echo $domain;

//by supplying no start or length arguments
//the string will be added to the beginning
$mystring = substr_replace("Hello World", "H3110 W0r1d!", 0, 0);
echo $mystring . "
";

//where if we did this:
$mystring = substr_replace("Hello World", "0 w0", 4, 4);
echo $mystring;
?>

No comments: