Vorrei dividere una stringa su un tag in parti diverse.PHP split o esplode stringa su <img> tag
$string = 'Text <img src="hello.png" /> other text.';
La funzione successiva non funziona ancora nel modo giusto.
$array = preg_split('/<img .*>/i', $string);
L'uscita dovrebbe essere
array(
0 => 'Text ',
1 => '<img src="hello.png" />',
3 => ' other text.'
)
Che tipo di modello devo usare per farlo fare?
MODIFICA Cosa succede se ci sono più tag?
$string = 'Text <img src="hello.png" > hello <img src="bye.png" /> other text.';
$array = preg_split('/(<img .*>)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
E l'uscita dovrebbe essere:
array (
0 => 'Text ',
1 => '<img src="hello.png" />',
3 => 'hello ',
4 => '<img src="bye.png" />',
5 => ' other text.'
)
È questo é piú attuale? Quando provo a echo questo codice vedo solo: 'array' – twan
@twan, come hai usato? – Federkun
L'ho già risolto, utilizzavo echo invece di print_r ($ array) lol. – twan