Welcome to PHPMule.com
A blog site which I am posting to during my learning of the popular programming language PHP. Feel free to leave comments!
-
PHP - Replacing Strings With Other Strings
This is a very useful function to include in web forms or anywhere where user’s can leave input. What this function does is replace strings with strings for example, replacing swear words with something else such as ‘****’. This can be easily done in PHP by using the following format:
str_replace(findwhat, replacewith, whichstring)
If we used this format we could produce the following:
$modifiedcomments = str_replace(”water”, ‘fire’, $comments);
echo $modifiedcomments;This will replace water with fire in the variable $comments. So when the script get’s processed a new variable called $modifiedcomments will be created and if it finds the word or string ‘water’ it will be replaced with ‘fire’.
(Post created on Wednesday, April 15th 09 at 21:55)
-
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jun | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||
Archives
Recent Articles
- PHP - Rounding Off Numbers
- PHP - Single vs Double Quotation Marks
- PHP - Loading Files Into Your PHP Script By Using require() and include()
- PHP - Replacing Strings With Other Strings
- PHP - Finding Strings Within Strings
- PHP - Using strlen() To Test String Length
- PHP - Using The explode() Function
- PHP - Changing The String Case
- PHP - The nl2br() Function
- PHP - Trimming Strings
Links
Categories
- PHP (22)
- Uncategorized (1)


