2016-05-02 1 views
1

J'essaie de preg_split après un mot et un deux-points.preg_split après un mot et un deux-points

qui fonctionne pour moi si je partage après un mot:

$split = preg_split('/\b(\w*WORD\w*)\b/', $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); 

Maintenant, je suis à la recherche de quelque chose à partager AFER mon mot + côlon. Comme Car:

+1

Il suffit d'ajouter ':' comme ceci: '/ (\ w * WORD \ w *): /'? PS: inutile d'utiliser les limites de mots '\ b' dans ce contexte. – HamZa

+0

Parfait :) fonctionne très bien – user1898361

Répondre

1

utiliser ceci:

votre appel:

modèle

: /\\b(\\w*WORD\\w*)\\b:/
sujet: a sentence before word WORD:a sentence after word

$returnValue = preg_split('/\\b(\\w*WORD\\w*)\\b:/', 'a sentence before word WORD:a sentence after word', -1, PREG_SPLIT_DELIM_CAPTURE); 

Résultat:

array (
    0 => 'a sentence before word ', 
    1 => 'WORD', 
    2 => 'a sentence after word', 
) 

et je suggère d'utiliser cet outil en ligne: https://www.functions-online.com/preg_split.html

+0

Thx pour l'outil de partage :) – user1898361