Created
August 7, 2017 13:34
-
-
Save kadko/99d30e2499f7eba630946b12da4fd79c to your computer and use it in GitHub Desktop.
Find from phrase to phrase in string and return or replace between
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function iki_ifade_arasi($str, $k1, $k2, $k1k2dahil=false, $replace){ | |
/* | |
$k1 ve $k2 arasındakileri döndürür (replace yoksa) | |
$k1 ve $k2 arasındakileri replace te verilen ile değiştirir (k1k2dahil true ise $k1, $k2 dahil olarak arasındaki değerler değiştirilir ) | |
$k1 ve $k2 arasındakileri replace te verilen ile değiştirir (k1k2dahil false ise sadece $k1 ve $k2 arasındaki değerler verilenle değiştirilir ) | |
$k1 ve $k2 den biri verilen $str yığınında bulunamazsa FALSE döndürür. | |
*/ | |
$p = strpos($str, $k1); | |
$p2 = strpos($str, $k2, ($p + strlen($k1))); | |
if( $p !== FALSE && $p2 !== FALSE){ | |
if( isset($replace) ){ | |
if($k1k2dahil == true){ | |
$pa1 = strlen($k1); $pa2 = -($p+strlen($k1)); | |
}else{ | |
$pa1 = 0; $pa2 = -($p-strlen($k2)); | |
} | |
return str_replace(substr($str, $p + $pa1, $p2+$pa2 ), $replace, $str); | |
}else{ | |
return substr($str, ($p + strlen($k1)), $p2 - ($p+strlen($k1)) ); | |
} | |
}else{ | |
return FALSE; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment