Created
August 16, 2019 14:08
-
-
Save lonalore/7e00a56003215461e23f37b5b1f3737e to your computer and use it in GitHub Desktop.
PHP split string on <img> tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = 'Text <img src="hello.png" > hello <img src="bye.png" /> other text.'; | |
$array = preg_split('/(<img[^>]+\>)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE); | |
// array(5) { | |
// [0]=> | |
// string(5) "Text " | |
// [1]=> | |
// string(22) "<img src="hello.png" >" | |
// [2]=> | |
// string(7) " hello " | |
// [3]=> | |
// string(21) "<img src="bye.png" />" | |
// [4]=> | |
// string(12) " other text." | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment