php

How to replace part of a string in PHP

In this tutorial, we are going to see how to replace part of a string in PHP. You can use PHP’s str_replace() function to find and replace any part of a string with another string. In the following example, the “best website” substring of the $str string is replaced with the “great platform” string.
 

How to replace part of a string in PHP
<?php
	$str = "Welcom to StackHowTo, it is the best website for learning";
	 
	// Display the replaced string
	echo str_replace("best website", "great platform", $str);
?>

Output:

Welcom to StackHowTo, it is the great platform for learning

 
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *