2017-05-03 12 views
-1
$text= "This is a text1 i want to replace before # text2 i want to replace 
before # text3" 

Start point ="text1" 
End point = "#" 
Replace= "@@@@@@" 

ノートに特定の文字の後の文字列を削除、変更文が 結果は、「これは私が#のテキスト3の前に削除したい@@@@@@テキスト2である」となりますですPHPは「私が前に交換したい」文字の前に

答えて

0

これは私がここに行っていることは、文字列の位置を見つけることであるあなたが

$mystring = "This is a text1 i want to replace before # text2 i want to replace before # text3"; 

$start = "text1"; 
$end = "#"; 
$replace= "@@@@@@"; 

$pos1 = strpos($mystring, $start); 
$pos2 = strpos($mystring, $end, $pos1); 

$length=$pos2+ strlen($end) - $pos1; 

$result = substr_replace($mystring,$replace,$pos1,$length); 
echo $result; 

を望むものです。 $ pos1 & $ pos2は、開始文字列と終了文字列の位置です。

次に、strlen($ end)が終了文字列の長さである2つの文字列の間の長さを計算します(終了文字列も取得できるようになります)。

最後に、通常のsubstr_replace関数を使用しました。

希望すると、これが役立ちます。

+0

ありがとうございました。私の問題を解決しました。 – user1130537

+0

ようこそ。あなたの問題を解決したので、答えを受け入れてください。 @ user1130537 –

関連する問題