You will discover in this course how to manipulate strings and the list of functions.
| Function | Description |
| strtolower() | rewrite in lowercase |
| strtoupper() | rewrite in uppercase |
| ucfirst() | rewrite in uppercase the initial |
| nl2br() | Replace the \n by <br> for display |
| htmlspecialshars() | Converts html characters |
| addslashes() | add an \ (slashe) before the special characters |
| stripslashes() | take off the slashes(\) |
| ltrim() | Deletes the original spaces |
| trim() | take off the first and the last spaces |
<?php
//give a simple sentence
$sentence = "PHP is a shareware scripting language";
//we print the sentence
print $sentence.'<br>';
//we will replace shareware by free
$sentence = str_replace("shareware","free",$sentence) ;
//we display the sentence after change
print $sentence;
?>
Output
PHP is a shareware scripting language
PHP is a free scripting language
<h3>Searching</h3>
[php]
<?php
//the sentence
$string = "PHP is a free scripting language";
//we check if the word free is in the sentence
if( ereg('free',$string))
{
//if yes we print ...
print 'Yes the word is in the sentence';
}
//else
else{
print '"free" is not in the sentence';
}
?>
Output
Yes the word is in the sentence
<?php
$string = "PHP is a free scripting language";
//we use the split() function to split the sentence by spaces available
$result = split(" ",$string);
//Caution: the result will be in an array form
print $result['3'].'<br>'.$result['5'];
?>
Output
free
language
<?php
//empty verify if the variable is defined
if(empty($variable_to_verify))
{
print "the variable is empty"; //error message variable empty
}
else{
print "it is ok"; //the variable is not empty
}
#-- the opposite of empty() is isset()
//isset verify if the variable is not empty
if( isset($variable_to_verify))
{
print "ok the variable is set";
}
else{
print "the variable is empty";
}
?>
thnk u for the good tutorial