Quelque chose comme ceci essentiellement travailler:
preg_split('/(<strong>|<b>)/', $html1, 3, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
Compte tenu de votre chaîne de test:
$html1 = '<strong>My content</strong>This is my content.<b>Some more bold</b>content';
vous finiriez avec
Array (
[0] => <strong>
[1] => My content</strong>This is my content.
[2] => <b>
[3] => Some more bold</b>content
)
Maintenant, si votre chaîne d'échantillon n'a pas commencé avec fort/b:
$html2 = 'like the first, but <strong>My content</strong>This is my content.<b>Some more bold</b>content, has some initial none-tag content';
Array (
[0] => like the first, but
[1] => <strong>
[2] => My content</strong>This is my content.
[3] => <b>
[4] => Some more bold</b>content, has some initial none-tag content
)
et un simple test pour voir si l'élément # 0 est soit une étiquette ou d'un texte pour déterminer où votre « deuxième étiquette et les années suivantes » commence texte (élément # 3 ou élément # 4)
serait-il possible de placer les divisions dans leur propre 'div' –