How To Use Strreplace Function With Example In PHP

admin_img Posted By Bajarangi soft , Posted On 24-09-2020

The str_replace() function  replace all the occurrences of the search string.

str_replace_Function

Syntax of str_replace() function and Usage

str_replace(search,replace,subject,count)


Parameter Values
 
search     -> Search for Specifies the value.

replace    -> The replacement value that replaces found search values.
 
subject    ->The string being searched and replaced on.

count      ->Optional. A variable that counts the number of replacements.


Let's learn

1.Create str_replace()

str_replace("car","bike","I like car")


2.Print string using str_replace() function.
echo str_replace("car","bike","I like car")

Example(1)
<?php
echo str_replace("car","bike","I like car");
?>


Complete Code of str_replace() Function:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP string replace function</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <div class="text-center">
        <h1>PHP str_replace() Function</h1>
    </div>
    <br>
    <h2>The str_replace() function  replace all the occurrences of the search string.</h2>
    <div class="well">
        <?php
        echo "<h4>".str_replace("car","bike","I like car")."</h4>";
        ?>
    </div>
    <br>
</div>
</body>
</html>

 

Related Post