I have a string
This is a text, "Your Balance left $0.10", End 0
how can i extract the string in between double quote and have only the text 'Your Balance left $0.10' (without the double quotes)
Tried preg_match_all but no luck
I have a string
This is a text, "Your Balance left $0.10", End 0
how can i extract the string in between double quote and have only the text 'Your Balance left $0.10' (without the double quotes)
Tried preg_match_all but no luck
Just use str_replace and escape the quote:
str_replace("\"","",$yourString);
Edit:
Sorry, didnt see that there was text after the 2nd quote. In that case, I'd simply to 2 searches, one for the first quote and one for the 2nd quote, and then do a substr to extra all stuff between the two.
The regular expression '"([^\\"]+)"'
will match anything between two double quotes.
$string = '"Your Balance left $0.10", End 0';
preg_match('"([^\\"]+)"', $string, $result);
echo $result[0];
You can do this easily using a regular expression. "([^"]+)"
will match the pattern
The brackets around the [^"]+
means that that portion will be returned as a separate match, which is what we want.
<?php
$str = 'This is a text, "Your Balance left $0.10", End 0';
//forward slashes are the start and end delimeters
//third parameter is the array we want to fill with matches
if (preg_match('/"([^"]+)"/', $str, $m)) {
print $m[1];
} else {
//preg_match returns the number of matches found,
//so if here didn't match pattern
}
//output: Your Balance left $0.10
Unlike other answers, this supports escapes, e.g. "string with \" quote in it"
.
$content = stripslashes(preg_match('/"((?:[^"]|\\\\.)*)"/'));