[ create a new paste ] login | about

Link: http://codepad.org/JqUspMPx    [ raw code | output | fork ]

PHP, pasted on Mar 7:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
echo str_replace_once('nothing', 'something', 'there is nothing to do, nothing to see');


function str_replace_once($str_pattern, $str_replacement, $string){
   
	if (strpos($string, $str_pattern) !== false){
		$occurrence = strpos($string, $str_pattern);
		return substr_replace($string, $str_replacement, strpos($string, $str_pattern), strlen($str_pattern));
	}
   
	return $string;
} 


Output:
1
there is something to do, nothing to see


Create a new paste based on this one


Comments: