1
$string = '$12.50 - This is my string';

これは私の文字列です$。php文字列関数を使用して最初のスペースからセクションを削除したいと思います。試しsubstrましたが、後に文字列が返されます$

出力は次のようになります。

- This is my string

文字列の最初の場所に$記号がない場合があるため、その場合は「This」が文字列から削除されます。

4

4 に答える 4

3
$sub = substr($string, strpos($string, " "));

strpos($string, " ") + 1その余分なスペースが必要かどうかによっては、使用する必要がある場合があります。

strposは、キャラクターの最初の出現を見つけます。)

于 2012-12-28T06:49:45.047 に答える
2
$string = '$12.50 - This is my string';
$string = strstr($string, ' ');

http://php.net/manual/en/function.strstr.php

于 2012-12-28T06:56:54.970 に答える
1

explodeを使用できます。

$string = '$12.50 - This is my string';
$test = explode(" ", $string, 2);
echo $test[1];
于 2012-12-28T06:51:37.130 に答える
0

preg_replaceの使用:

$string = '$12.50 - This is my string';

echo preg_replace('/^(.*?)\s/', '', $string);
于 2012-12-28T10:28:15.537 に答える