Send CathInfo's owner Matthew a gift from his Amazon wish list:
https://www.amazon.com/hz/wishlist/ls/25M2B8RERL1UO

Author Topic: Any PHP developers out there?  (Read 857 times)

0 Members and 1 Guest are viewing this topic.

Offline Matthew

  • Mod
  • *****
  • Posts: 31182
  • Reputation: +27095/-494
  • Gender: Male
Any PHP developers out there?
« on: April 05, 2016, 01:31:05 PM »
  • Thanks!0
  • No Thanks!0
  • Yes, I know I'm a PHP developer. But some problems are tougher than others, and I'd prefer to have help if someone's already solved this problem.

    My problem:

    Updating preg_replace (with the /e modifier) with preg_replace_callback.

    http://stackoverflow.com/questions/15454220/replace-preg-replace-e-modifier-with-preg-replace-callback

    My new server, as well as my local Linux server, both use a very recent version of PHP that is higher than v5.5. That means preg_replace with "/e" is deprecated -- I can't use it anymore.

    Regarding the conversion that needs to be done, I understand SOME of it, maybe even MUCH of it, but I'm still having a problem with certain instances of this switchover.

    I found this code, which is SUPPOSED to be a drop-in replacement for all existing cases, but it's not perfect I guess.

    // for PHP 5.5.0 - Replacement of preg_replace and pattern modifier "e" with preg_replace_callback
    function php55_callback($element)
    {
       return str_replace(
          array(''$1$3'',''$2$4'',''$1'', ''$2'', '$1', '$2'),
          array('$matches[1].$matches[3]','$matches[2].$matches[4]','$matches[1]','$matches[2]','$matches[1]','$matches[2]'),
          $element);
    }

    //Separate patterns with "e" modifier and without
    function php55_preg_replace($pattern, $replace, $text)
    {
       //if not PHP 5.5.x no changes
       if(version_compare(PHP_VERSION, '5.5.0', '<'))
          return preg_replace($pattern, $replace, $text);

       if(!is_array($pattern)) {
          $pattern = array($pattern);
          $replace = array($replace);
       }
       $count = count($pattern);
       $pattern_normal = $replace_normal = array();
       for($i = 0; $i < $count ; $i++)
       {
          if(substr($pattern[$i],-1) == "e")
             $text = preg_replace_callback(substr($pattern[$i],0,-1), create_function('$matches','return '.php55_callback($replace[$i]).';'), $text);
          else
          {
             $pattern_normal[] = $pattern[$i];
             $replace_normal[] = $replace[$i];
          }
       }
       return preg_replace($pattern_normal, $replace_normal, $text);
    }

    Here is the code where the problem is:
    (You'll have to "quote" my post and get the actual code out; I can't stop the board from formatting for smilies, formatting, etc. That's why a bunch of the code here has "strikethrough"...)

          if (($options & FORMAT_MBCODE) && $brackets) {
             $search = array(
                '~[(/)?([bi])]~i',
                '~~i',
                '~~i',
                '~[/[us]]~i',
                '~http://(h t t p|h t t p s|f t p) : / /(.+?)~ise',
                '~(.+?)~ise',
                '~([a-z0-9-_.]+@[a-z0-9-.]+.[a-z0-9-_.]+)?~i',
                '~+?)](.*?)~i',
                '~~ise',
                '~[youtube](h t t p|h t t p s|f t p) : / /(.*?)[/youtube]~ise',
                '~[(right|center)](.*?)[/1]~is',
                '~
    Code: [Select]
    (.*?)~ise',
                '~(.*?)~ise',
                '~[php=([0-9]+?)](.*?)[/php]~ise',
                '~[color=([A-Za-z ]+?)](.*?)[/color]~is',
                '~[font=([A-Za-z ]+?)](.*?)[/font]~is',
                '~[size=([1-9]+?)](.*?)[/size]~is'
             );

             // <iframe width="432" height="243" src="https://www.youtube.com/embed/usHOxIkanHY?rel=0" frameborder="0" allowfullscreen></iframe>

             $replace = array(
                '<12>',
                '<span style='text-decoration:underline'>',
                '<span style='text-decoration:line-through'>',
                '</span>',
                ''<a href="' . str_replace(' ', '', '1://2') . '" onclick="window.open(this.href,'' . $this->sets['link_target'] . '');return false;">' . str_replace(' ', '', '1://2') . '[/url]'',
                ''<a href="' . str_replace(' ', '', '1://2') . '" onclick="window.open(this.href,'' . $this->sets['link_target'] . '');return false;">' . str_replace('"', '"', '3') . '[/url]'',
                '1',
                '2',
                ''<img src="' . str_replace(' ', '', '1://2') . '" width="500" alt="' . str_replace(' ', '', '1://2') . '" />'',
                ''<iframe src="' . str_replace(' ', '', '1://2') . '" width="500" height="315" alt="' . str_replace(' ', '', '1://2') . '" frameborder="0" allowfullscreen></iframe>'',
                '<div align="1">2</div>',
                '$this->format_code('1', 0)',
                '$this->format_code('1', 1)',
                '$this->format_code('2', 1, '1')',
                '<span style='color:1'>2</span>',
                '<span style='font-family:1'>2</span>',
                '<span style='font-size:1ex'>2</span>'
             );

             if ((substr_count($in, '
    Quote
    ') + substr_count($in, '
    Quote from: ')) == substr_count($in, '[/quote
    ')) {
                $search[] = '~
    Quote from: (.+?)
    ~i';
                $search[] = '~
    Quote
    ~i';
                $search[] = '~
    ~i';

                $replace[] = '<table style="width:90%; margin-left:5%; margin-right:5%;" border="0" cellpadding="3" cellspacing="0"><tr><td>1 ' . $this->lang->main_said . ':</td></tr><tr><td class="quote">';
                $replace[] = '<table style="width:90%; margin-left:5%; margin-right:5%;" border="0" cellpadding="3" cellspacing="0"><tr><td>' . $this->lang->main_quote . ':</td></tr><tr><td class="quote">';
                $replace[] = '</td></tr></table>';
             }

             $in = $this->php55_preg_replace($search, $replace, $in);

    Want to say "thank you"? 
    You can send me a gift from my Amazon wishlist!
    https://www.amazon.com/hz/wishlist/ls/25M2B8RERL1UO

    Paypal donations: matthew@chantcd.com


    Offline ihsv

    • Full Member
    • ***
    • Posts: 690
    • Reputation: +931/-118
    • Gender: Male
    Any PHP developers out there?
    « Reply #1 on: April 05, 2016, 01:53:56 PM »
  • Thanks!0
  • No Thanks!0
  • Matthew, have you tried contacting Liquidweb about this?  Just let them know you moved over to their servers and you're having trouble with X, Y or Z.  I think you'll be surprised with their "Best Effort" support.

    Quote from: Best Effort Support

    Our fully managed hosting options offer a lot in terms of products and support. But did you know that in addition to what is covered with our on-site 24/7/365 Heroic Support, we also offer Best Effort Support? Best Effort Support means that we will try to solve any problem you have with your server, software, or hardware - even if it’s something not traditionally covered in our managed support.


     www.liquidweb.com/support/best-effort.html
    Confiteor unum baptisma in remissionem peccatorum. - Nicene Creed


    Offline Matthew

    • Mod
    • *****
    • Posts: 31182
    • Reputation: +27095/-494
    • Gender: Male
    Any PHP developers out there?
    « Reply #2 on: April 05, 2016, 05:06:28 PM »
  • Thanks!0
  • No Thanks!0
  • Here is a test of several tags used on CathInfo:

    1. Blue text


    2. Large Text


    3. How about in a font.

    4. How about bold?

    5. Or Italic?

    6. Or Underlined?


    7. Or Struckout?

    8. Or PHP

    Quote
    9. And here's a quote.


    10. Here is a link to a site:
    10. CNN

    Youtube video:
    [youtube]https://www.youtube.com/embed/-3cb7C_FbwA[/youtube]

    Img tag:


    Testing an attached image:
    Want to say "thank you"? 
    You can send me a gift from my Amazon wishlist!
    https://www.amazon.com/hz/wishlist/ls/25M2B8RERL1UO

    Paypal donations: matthew@chantcd.com

    Offline Croix de Fer

    • Sr. Member
    • ****
    • Posts: 3219
    • Reputation: +2525/-2210
    • Gender: Male
    Any PHP developers out there?
    « Reply #3 on: April 05, 2016, 05:38:43 PM »
  • Thanks!0
  • No Thanks!0
  • Does AlligatorDicax (CathInfo member) know how to develop it? Try to contact him to see if he can help you.

    Blessed be the Lord my God, who teacheth my hands to fight, and my fingers to war. ~ Psalms 143:1 (Douay-Rheims)

    Offline AlligatorDicax

    • Full Member
    • ***
    • Posts: 908
    • Reputation: +372/-173
    • Gender: Male
    Any PHP developers out there?
    « Reply #4 on: April 15, 2016, 03:20:46 PM »
  • Thanks!0
  • No Thanks!0
  • Quote from: ascent (Apr 5, 2016, 5:38 pm)
    Does AlligatorDicax (CathInfo member) know how to develop it?

    I haven't visited CathInfo in many days--maybe on the order of 2 weeks--so this is the first I'd seen of Matthew's inquiry.

    I regret that the simplest answer I can offer to the inquiry-as-intended is "no".

    That's to say, what you're doing, and the extent to which you're doing it, is beyond my experience.  What little PHP code I've written lately is via a PHP version that seems farther back than yours, developed on Windows PC, altho' it's hosted on a server running PHP 5.4 (last I looked).  No contact with version 5.5-or-later at all.  And no coding using call-backs, even tho' the WinHelp I have claims implementation waaay back in PHP &#62;=4.0.5 (I suppose they're involved in user-&-forum management via MySQL for MercuryBoard).

    I've been delaying various 'to-do' projects because of a certain demand on my time that I assumed was imminent, which hasn't yet appeared.