$string = '$12.50 - This is my string';
これは私の文字列です$
。php文字列関数を使用して最初のスペースからセクションを削除したいと思います。試しsubstr
ましたが、後に文字列が返されます$
。
出力は次のようになります。
- This is my string
文字列の最初の場所に$記号がない場合があるため、その場合は「This」が文字列から削除されます。
$sub = substr($string, strpos($string, " "));
strpos($string, " ") + 1
その余分なスペースが必要かどうかによっては、使用する必要がある場合があります。
(strposは、キャラクターの最初の出現を見つけます。)
$string = '$12.50 - This is my string';
$string = strstr($string, ' ');
explodeを使用できます。
$string = '$12.50 - This is my string';
$test = explode(" ", $string, 2);
echo $test[1];
preg_replaceの使用:
$string = '$12.50 - This is my string';
echo preg_replace('/^(.*?)\s/', '', $string);