Advertisement
ShawnsSpace

php preg_replace wrap image tag with div tag.

Jun 9th, 2016
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.36 KB | None | 0 0
  1. <?php
  2. $image = '<img src="https://scontent.xx.fbcdn.net/v/t1.0-1/c0.10.50.50/p50x50/1004887_10152095356034577_1114229542_n.jpg?oh=ecfa80ac5282239d227a90be229dae32&oe=57D3FE41" />';
  3. function wrapimg($str){
  4. $str = preg_replace("{<img\\s*(.*?)src=('.*?'|\".*?\"|[^\\s]+)(.*?)\\s*/?>}ims", '<div><img $1src=$2 $3/></div>', $str);
  5. return $str;
  6. }
  7. echo wrapimg($image);
  8. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement