Extract string between two characters
Snippet for extracting a string between two characters
function extractStringBetween($cFirstChar, $cSecondChar, $sString)
{
preg_match_all("/\\".$cFirstChar."(.*?)\\".$cSecondChar."/", $sString, $aMatches);
return $aMatches[1];
}
$sMyString = "Bitte alle eingeklammerten Begriffe extrahieren: [Symfony] [CodeIgniter] #PHP# [Zend]";
var_dump(extractStringBetween("[", "]", $sMyString));
/*
* Ausgabe:
*
array(3)
{
[0]=>
string(7) "Symfony"
[1]=>
string(11) "CodeIgniter"
[2]=>
string(4) "Zend"
}
*/
Url: http://sklueh.de/2012/09/text-zwischen-zwei-zeichen-extrahieren/
Language: PHP | User: sklueh | Created: Sep 24, 2013