文字列を置換する

str_replace()関数を使い、文字列を置換することができます。

◆書式

str_replace( 引数1, 引数2, 引数3 )

【詳細】
戻り値(str)
	置換後の文字列です。
引数1(str1)
	置換前の文字列です。
引数2(str2)
	置換後の文字列です。
引数3(str3)
	置換対象の文字列です。

 

◆サンプルコード

<?php

$test = "test_NG";

echo str_replace( "NG", "OK" , $test);"test_OK" と表示されます。

?>

 

[対象]
PHP 5.x