SQL PHP HTML ASP JavaScript articles and free scripts to download
 

PHP case in sensitive String Replace

The main difference between str_replace and str_ireplace is str_replace is a case sensitive string replacement and str_ireplace is a case in-sensitive string search and replacement.

str_ireplace function in PHP when applied to a main string, it searches for occurrence of a string and replace them by another string.

This function can take an array as search string and each element of the array if present is replaced by another string. We can try with an example. If you are searching for a simple example then you can see str_replace function. Here is a sample code which takes an array of search words and replaces them by another word within a string.

$search = array("good", "php", "html", "ASP");
$final_string = str_replace($search, "*", "All good sites uses PHP along with HTML or they use ASP and html");
echo $final_string;


As we have seen here we can use an array as search terms and all the elements of the array can be replaced by a replace string. We can also use another array as replacement array and each element is replace by matching element from replacement array, if not element is found then blank string is replaced. Here is the script code for that

$search = array("good", "php", "html", "asp");
$replace=array("GOOD","PHP","HTML","ASP","NO");
$final_string = str_replace($search, $replace, "All good sites uses PHP along with HTML or they use asp and html");
echo $final_string;

Discuss this tutorial at forum


PHP String Functions
All String Functions in PHP
str_replace: How to replace a part of a string with another string
str_ireplace: Case in-sensitive search and replace using array of strings
strlen: How to find length of a string in PHP?
trim: Removing empty space from both sides of a string
strrev: Reversing a string by using strrev function in PHP
Adding two or more strings in PHP
stristr: Searching for a presence of a string inside another string
nl2br: Adding Line breaks inside a string in place of carriage returns
split: Breaking a string to form array using delimiters
substr: Collecting part of a string
substr_count: Counting occurrence of sub string in main string
str_repeat: Repeating a string number of times
strtolower(): function to change alphabets to Lower case
strtoupper(): function to change characters to upper case letters
function to collect part of a string with two landmarks
Random string generator with number and alphabets for password
strcasecmp(): Case insensitive string comparison
strcmp(): Case sensitive string comparison
str_pad(): String pad with specified length
md5 hash of a string: encryption of a string
Separating domain and userid part from an email address using split
htmlspecialchars: Printing html special chars to the page
strip_tags: Removing html tags within a string
ucwords: Removing html tags within a string



 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
String Functions
htmlspecialchars
md5 hash
nl2br
Random string
strip_tags
str_replace
str_ireplace
strlen
strrev
stristr
split
substr
substr_count
str_repeat
strtolower
strcasecmp
strcmp
str_pad
trim
ucwords
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.