Finché il formato rimane lo stesso si può fare questo usando un'espressione regolare. "([^"]+)"
corrisponderà il modello
- doppio citazione
- Almeno un non-virgolette doppie
- doppio citazione
Le parentesi intorno alla [^"]+
significa che tale parte verrà restituito come un gruppo separato.
<?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
fonte
2009-06-19 09:28:09
È possibile trovare ['s ($ str) -> tra ('"', '"')'] (https: // github.com/delight-im/PHP-Str/blob/8fd0c608d5496d43adaa899642c1cce047e076dc/src/Str.php # L412) utile, come trovato in [questa libreria standalone] (https://github.com/delight-im/PHP-Str). – caw