1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Pulling first image from thread

Discussion in 'XenForo Development Discussions' started by NixFifty, Aug 10, 2014.

  1. NixFifty

    NixFifty Well-Known Member

    Working on a little project and came across a bit of a hurdle.

    I was wondering if anyone had any ideas how I could go about programatically pulling the first image in a thread. So for instance, pulling the contents of the first occurrence of the IMG BBCode.

  2. Aayush

    Aayush Well-Known Member

    1. Get the thread with the first post
    2. Parse the first post or regex to find the IMG BBCode
    3. Do whatever you want to do with it!

    PS: I actually dealt with a pretty similar problem recently. I just checked if the thread's first post had an attachment and I fetched the first attachment which was of image type.
  3. NixFifty

    NixFifty Well-Known Member

    I might try attachments as it sounds a lot easier to achieve what I want but then using IMG BBCode, I'll probably learn a few new things too, haha.

    Do you happen to know a good place where I can read up more on regular expressions? I'm pretty basic at the moment.
  4. Aayush

    Aayush Well-Known Member

    Regex are always tough! :p

    Some good resources that I used personally to get over the fear of Regex are:
    1. Tutsplus tutorials. I don't remember exactly but I think they were by Jeffery way, have a look around that site and you might just find it. Think those tuts could date back 2-4 years from now.
    2. regex101.com -> Great tool for testing out regular expressions. It's much better than doing it in PHP and trying to to see if it works or not.

    Besides that all you need to be pro at regular expression is a lot of practice. Once you get a hang of it, you will always think why hadn't you figured them out before ;)
    NixFifty likes this.

Share This Page