php - How to remove plain text from a string after using strip_tags() -
so have string , used strip_tags() function remove tags except img still have plain text next img element. here visual example
$myvariable = "this text needs removed<a href='blah_blah_blah'>blah</a><img src='blah.jpg'>" so using php strip_tags() able remove tags except <img> tag (which want). thing didn't remove text.
how remove left on text? text either before tag or after tag
[added more details]
$description = 'crazy stuff<a href="https://websta.me/p/1337373806024694030_327078936"><img src="https://scontent.cdninstagram.com/t51.2885-15/e15/14287934_1389514537744146_673363238_n.jpg?ig_cache_key=mtmznzm3mzgwnjayndy5ndazma%3d%3d.2"></a>'; that's variable holding.
thanks in advance
instead of replacing can extract values want:
(<(\w+).+</\2>) to used preg_match(), see a demo on regex101.com.
in php:
<?php $regex = '~(<(\w+).+</\2>)~'; $string = 'crazy stuff<a href="https://websta.me/p/1337373806024694030_327078936"><img src="https://scontent.cdninstagram.com/t51.2885-15/e15/14287934_1389514537744146_673363238_n.jpg?ig_cache_key=mtmznzm3mzgwnjayndy5ndazma%3d%3d.2"></a>here well'; if (preg_match($regex, $string, $match)) { echo $match[1]; } ?>
Comments
Post a Comment