eval.in

Paste #3553

PHP — PHP 5.4.6, pasted 1 year ago

1
2
3
4
5
6
7
<?php

$string = '<p>First sentence here comes.&nbsp; Second sentence here it is.&nbsp; One more sentence.&nbsp;&nbsp;</p> <img alt="amj" src="https://domain.com/images7.jpg" /> <img alt="Ea" src="http://domain.com/images3.jpg" /> <img alt="amj" src="https://domain.com/images7.jpg" /> <img alt="amj" src="https://domain.com/images7.jpg" />';

$result = preg_split('/(<img [^>]*>)/', $string, null, PREG_SPLIT_DELIM_CAPTURE);

print_r($result);

Program Output

Array
(
    [0] => <p>First sentence here comes.&nbsp; Second sentence here it is.&nbsp; One more sentence.&nbsp;&nbsp;</p> 
    [1] => <img alt="amj" src="https://domain.com/images7.jpg" />
    [2] =>  
    [3] => <img alt="Ea" src="http://domain.com/images3.jpg" />
    [4] =>  
    [5] => <img alt="amj" src="https://domain.com/images7.jpg" />
    [6] =>  
    [7] => <img alt="amj" src="https://domain.com/images7.jpg" />
    [8] => 
)

OK (0.004 sec real, 0.006 sec wall, 13 MB, 126 syscalls)

Fork