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

Post content replace help

Discussion in 'XenForo Questions and Support' started by Ingenious, Apr 21, 2013.

  1. Ingenious

    Ingenious Well-Known Member

    I'm trying to tidy up some very old posts over 10 years old, which were converted from Ikonboard to vB to Xenforo, but appear to contain HTML. So, the HTML appears in the actual post as plain text. Some of this is simple replace, like the </font> and <table> tags, plus some of the smilies (which were saved in the database as IMG BBCode). I can just find and remove these.

    But some have the equivalent of wildcards, so wondering what to do, example:

    Code:
    <font color='#F660AB'>
    The color being different with various posts.

    I need to replace <font color=*> with ' ' (nothing).

    The other one is the exotic smilies. I can do a simple search/replace, for example, find:

    Code:
    [IMG]http://www.my-forum-url/iB_html/non-cgi/emoticons/smile.gif[/IMG]
    With:

    Code:
    :)
    But for the remainder (all the odd smilies not covered by the basic ones in XF), I need to do the equivalent of finding and removing:

    Code:
    [IMG]http://www.my-forum-url/iB_html/non-cgi/emoticons/*[/IMG]

    I guess I can run an update/replace MySQL command for the static ones via PHPMyAdmin but what about the wildcard ones? Any scripts out there which can do this for me? Alternatively, I can use Kier's post search/replace add-on, but I'd need someone to advise on the PCRE expressions to use please for the two examples above, as it's all Greek to me :)
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  3. Ingenious

    Ingenious Well-Known Member

    Thanks Jake. I don't need to replace font with colour, so what would I need to enter in those fields just to replace <font color=*> with nothing?

    What does #siU mean?
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Quick Find: [IMG]http://www.my-forum-url.com/iB_html/non-cgi/emoticons/

    Regular Expression: #\[IMG\]http://www\.my-forum-url\.com/iB_html/non-cgi/emoticons/.*\[/IMG\]#siU

    Replacement String: <nothing here, leave it empty>

    That will completely remove all matching IMG tags.
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Quick Find: <font

    Regular Expression: #<font color='([^']+)'>(.*)</font>#siU

    Replacement String: \2

    That will leave only the text that was previously colored, but now it won't have any color tag.
     
  6. Ingenious

    Ingenious Well-Known Member

    Thanks Jake :)
     
  7. Francesco V.

    Francesco V. Active Member

    How can i replace links like this
    Code:
    [YT]http://www.youtube.com/watch?v=EBJ74xWl4fs[/YT]
    with the xenforo code to see youtube video ?
    I found these entries in old post, maybe they were generated by an old custom vbulletin plugin.
     
  8. Jeremy

    Jeremy XenForo Moderator Staff Member

    Try:

    regular expression:
    #[YT](.*)[/YT]#siU

    Replacement:
    [media=youtube]\1[/media]
     
  9. Francesco V.

    Francesco V. Active Member


    hummm...in the test run it grab a lot of string that are not interested in the replacement. Maybe what i inserted in quick search is wrong ?
    In inserted:

    Code:
    [YT
     
  10. Jeremy

    Jeremy XenForo Moderator Staff Member


    RegEx: #\[YT\](.*)\[/YT\]#siU

    That should work.
     
  11. Francesco V.

    Francesco V. Active Member

    thanks this worked ! Anyway a bug i faced one time during migration occured again. I dont' see the youtube video in post but if i edit the post i see the media code. If i simply click save and exit, the existing media code is embedded in another media code

    Code:
    [media=youtube][media=youtube]video url[/media][/media]
    anyway i'll stick with this issue, not so important.
     
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    The replacement might have been bad. I would need to see the original posting code in context to know for sure.
     
  13. W1zzard

    W1zzard Well-Known Member

    Sorry for reviving such an old thread, the better regex to convert [yt tags is

    Code:
    #\[YT\]([A-Za-z0-9_\-]{11})\[/YT\]#siU
    This ensures that only proper YT embeds with a YouTube ID in them get replaced, the regexp further up in the thread will replace everything, including people talking about the yt tag
     

Share This Page