Beginner Friendly · Hands-on · Free
Replaces some character of the string with other characters
str_replace() function நாம் கொடுக்கும் string இல் உள்ள characters களை மற்றொரு character களால் replace செய்வதற்கு பயன்படுகிறது.
5 min read
Updated Dec 02, 2025
<h1>str_replace() Function in PHP</h1>
<p>str_replace() function நாம் கொடுக்கும் string இல் உள்ள characters களை மற்றொரு character களால் replace செய்வதற்கு பயன்படுகிறது.
</p>
<p class="tag">str_replace ( search, replace, string, count) </p>
<div class="alert alert-success">
<strong>Note: </strong>str_replace() function நான்கு argument கள் அனுபப்படுகிறது. அவைகள் முறையே search, replace, string மற்றும் count ஆகியன.
இங்கு முதல் argument search செய்ய வேண்டிய string ஆனது அனுபப்படுகிறது. இரண்டாவது replace செய்யவேண்டிய string, மூன்றாவது argument original string. நான்காவது argument எவ்வளவு string கள் replace ஆனது என்பதன் எண்ணிக்கை அதாவது அதன் count ஐ தருகிறது. முக்கியமாக இந்த function case-sensitive முறையை பின்பற்றுகிறது.
</div>
<h1>Example1</h1>
<div class="try-code">
<pre>
<code class="php"><?php
$string = "Hi everyone!";
$search = 'Hi';
$replace = 'Hello';
$newstr = str_replace($search, $replace, $string, $count);
echo $newstr;
echo $count;
?>
</code>
</pre>
</div>
<p>
மேலே உள்ள Example1-ஐ கவனிக்கவும் $string என்ற variable-இல் "Hi everyone!" என்ற string உள்ளது. $search என்ற variable இல் 'Hi' என்ற string மற்றும் replacement செய்யவேண்டிய string 'Hello' என கொடுகபட்டுள்ளது. நான்காவது argument ஆனது string எவ்வளவு முறை replace ஆகியுள்ளது என்பதன் எண்ணிக்கையை கொடுக்கிறது. இங்கு "Hi everyone!" என்ற string ஆனது Hello everyone! என்று replace ஆகி நமக்கு output ஆக கிடைக்கிறது.
$count variable இல் அதன் எண்ணிக்கையை காட்டுகிறது.
</p>
<div class="output_code">
<strong>Output:</strong>
<pre>
Hello everyone!
1
</pre>
</div>
<h1>Example2</h1>
<div class="try-code">
<pre>
<code class="php"><?php
$string = "Happy Morning";
$search = 'Happy';
$replace = 'Good';
$newstr = str_replace($search, $replace, $string, $count);
echo $newstr;
echo $count;
?>
</code>
</pre>
</div>
<p>
மேலே உள்ள Example2-ஐ கவனிக்கவும் $string என்ற variable-இல் "Happy Morning" என்ற string உள்ளது. $search என்ற variable இல் 'Happy' என்ற string மற்றும் replacement செய்யவேண்டிய string 'Good' என கொடுகபட்டுள்ளது. நான்காவது argument ஆனது string எவ்வளவு முறை replace ஆகியுள்ளது என்பதன் எண்ணிக்கையை கொடுக்கிறது. இங்கு "Happy Morning" என்ற string ஆனது Good Morning என்று replace ஆகி நமக்கு output ஆக கிடைக்கிறது.
$count variable இல் அதன் எண்ணிக்கையை காட்டுகிறது.
</p>
<div class="output_code">
<strong>Output:</strong>
<pre>
Good Morning
1
</pre>
</div>
இது பற்றிய தங்களின் கருத்துகளை இங்கே பதிவிடுங்கள் . இது பயனுள்ளதாக விரும்பினால் மற்றவர்களுக்கும் இதை share செய்யுங்கள்.