Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to add a DIV to this JS code

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40259
    farzadina
    Participant

    I have a comment embedder plugin that allow my users to upload a photo with their comments. Now I want to give that photo, a special DIV. Here is its main code:

    function embed_images($content) {
    $content = preg_replace(‘/[img=?]*(.*?)([/img)?]/e’, ‘”“‘, $content);
    return $content;
    }

    Where to add the DIV?
    *the image add with a[img][/img] shortcode to the comment.

    #111739
    Medros
    Member

    There’s a few easy ways to handle this. You could wrap your $content with a string “

    ” + preg…. + “

    “; Or more simply add another line after $content.

    function embed_images($content) {
    $content = preg_replace(‘/[img=?]*(.*?)([/img)?]/e’, ‘”“‘, $content);
    $content = “

    ” + $content + “

    “;
    return $content;
    }

    The second options would be simpler to read. Also this is just a php way of doing it, If you wanted to you could have a js library handle the images and wrap them as well.

    #111740
    Medros
    Member

    Oh wow markdown stipped the first examle.

    $content = “

    ” + preg_replace(‘/[img=?]*(.*?)([/img)?]/e’, ‘”“‘, $content) + “;
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.