2 Replies - 141 Views - Last Post: 08 April 2019 - 03:46 AM Rate Topic: -----

#1 Volothamp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-April 19

Is it possible to use a function inside an array?

Posted 08 April 2019 - 02:33 AM

I am currently trying to add a code tag to my bbcode script, without much success.
<?php
function bbCode($content)
{
    $search = array(
        '~\[code\](.*?)\[/code\]~s',
        '~\[img=(.*?)\]~s'
    );

    // Row 12, 13, 14, and 15 are different versions of row 12 I have tried.
    $replaceWith = array(
        highlight_string('$1') // Causes $1 to pop up everywhere on the webpage, even where it shouldn't. Tag is replaced with a 1.
        highlight_string($1) // HTTP Error 500.
        highlight_string("$1") // Same as first row.
        highlight_string(search[0], 8, -11) // As the first row, but (.*?) pops up instead of $1
        '<img src="$1">'
    );
    
    return preg_replace($search, $replaceWith, $content);
}
Is there a "simple" way to get this to work? The [img] tag works as intended, and more tags will be added later. But for now I am trying to get the [code] tag to work.

Anyone have any idea?

Is This A Good Question/Topic? 0
  • +

Replies To: Is it possible to use a function inside an array?

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4226
  • View blog
  • Posts: 13,399
  • Joined: 08-June 10

Re: Is it possible to use a function inside an array?

Posted 08 April 2019 - 02:57 AM

have you tried http://php.net/preg-replace-callback ?
Was This Post Helpful? 0
  • +
  • -

#3 Volothamp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-April 19

Re: Is it possible to use a function inside an array?

Posted 08 April 2019 - 03:46 AM

No, but I'll give it a go when I get home! Hopefully I can get it to work! Thanks for the tip!

This post has been edited by Dormilich: 08 April 2019 - 05:58 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1