Reputation: 151
$string = '$12.50 - This is my string';
This is my string & I want remove section from $
to first space using php string function. I have tried substr
but it returns me string after $
.
Output should be as below:
- This is my string
In some cases there is no $ sign ain first place of string so in those cases "This" is removed from string.
Upvotes: 1
Views: 311
Reputation: 2291
You can use explode.
$string = '$12.50 - This is my string';
$test = explode(" ", $string, 2);
echo $test[1];
Upvotes: 1
Reputation: 2335
Using preg_replace:
$string = '$12.50 - This is my string';
echo preg_replace('/^(.*?)\s/', '', $string);
Upvotes: 0
Reputation: 342
$string = '$12.50 - This is my string';
$string = strstr($string, ' ');
http://php.net/manual/en/function.strstr.php
Upvotes: 2