SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    toronto
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    BBCode and CSS Formatting

    I want to store the content of a web site in the database, so I am using BBCode for the links, images, etc.

    I need the following result:

    <img class="blockcenter" src = "elements/Canadian_Flag.jpg" alt="Canadian_Flag.jpg" >
    /* CSS centers the image */

    from the BBCode:

    [img]class="blockcenter" src = "elements/Canadian_Flag.jpg" alt="Canadian_Flag.jpg"[/img]

    I get:

    <img src=" class="blockcenter" photos/atackadstargetyoy.jpg" alt="Canadian_Flag.jpg" />

    So you see how it is mangled.

    I am not sure if there is a solution in the PHP, I suspect it is in using something different for my CSS to center images. But it is close to midnight in Toronto and I am tired I hope it is a quick spot and someone can get me going again.

    Thanks
    Stephen
    Last edited by ralph.m; Apr 16, 2013 at 21:26.
    Stephen

  2. #2
    SitePoint Member angelfire's Avatar
    Join Date
    Feb 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in php there are functions for handling BBCode. there is a function BBCode_Create to create BBCode which returns a value that has to be used with the function bbcode_parse(<return value from bbcode_create>, [img]class="blockcenter" src = "elements/Canadian_Flag.jpg" alt="Canadian_Flag.jpg"[/img]); this should return the required image tag.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    toronto
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I saw that but didn't quite understand it.

    But I was able to find a CSS solution that is much easier. The content is within a div called middle.

    #middle img { display: block; margin-left: auto; margin-right: auto }
    Stephen

  4. #4
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stephend View Post
    I want to store the content of a web site in the database, so I am using BBCode for the links, images, etc.

    I need the following result:

    <img class="blockcenter" src = "elements/Canadian_Flag.jpg" alt="Canadian_Flag.jpg" >
    /* CSS centers the image */

    from the BBCode:

    [img]class="blockcenter" src = "elements/Canadian_Flag.jpg" alt="Canadian_Flag.jpg"[/img]
    bbcode is best used to simplify the code that the end user has to type to a bare minimum. Giving someone a bbcode that takes 3 attributes defeats the purpose of making it bbcode in the first place. If I were tackling this I'd make the bbcode simply

    Code:
    [flag]Canada[/flag]
    And whatever definitions file deciphers the flag bbcode knows what the target image is, and what the alt text is (which should by the way be something like "Image of the National Flag of Canada" - not the filename - alt is for text readers, particularly those for the blind, so a filename is pointless as alt text.

  5. #5
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stephend View Post
    Thank you. I saw that but didn't quite understand it.

    But I was able to find a CSS solution that is much easier. The content is within a div called middle.

    #middle img { display: block; margin-left: auto; margin-right: auto }
    Simpler still...

    #middle img { display: block; margin: 0 auto; }

    Or change the 0 to what you want the top and bottom margins to be.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    toronto
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by angelfire View Post
    in php there are functions for handling BBCode. there is a function BBCode_Create to create BBCode which returns a value that has to be used with the function bbcode_parse(<return value from bbcode_create>, [img]class="blockcenter" src = "elements/Canadian_Flag.jpg" alt="Canadian_Flag.jpg"[/img]); this should return the required image tag.
    I have failed to get this working.

    The examples on the PHP manual site do not address getting the image file and alt value from within the [img][/img] pair.
    Stephen

  7. #7
    SitePoint Member angelfire's Avatar
    Join Date
    Feb 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for the purpose of getting image file and alt value from within the [img][/img] pair you need to use regular expression. If using php you can use for example preg_match('[img] src=(.*?\.jpg) alt=(.*?)[/img]',$data, $match); where $match[0] and $match[1] will give you the required value.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •