0

I'm trying to parse code and swap out the usage of a method for a helper function. There's more processing that I need to do with the actual parameters passed to the method, so I plan on using preg_replace_callback.

Right now the code that I am trying to parse looks like this

<a class="button expanded" href="#contact">
<?= $this->Languages_model->trans( "Text Here!", $this->language->lid ); ?> 
more <?= $this->Languages_model->trans( "Additional Text (C)", $this->language->lid ); ?></a>

What I'd like to match is the method calls:

$this->Languages_model->trans( "Text Here!", $this->language->lid );
$this->Languages_model->trans( "Additional Text (C)", $this->language->lid );

I'm currently using the following regex, but it's not working for me.

$regex = '|\$this\->Languages_model\->trans\(.*\);|sm';

Using the regex without the flags, returns what I want, provided that the methods are used on separate lines, but this can't be guaranteed. Otherwise it matches from the start of the first method to the end of the second.

There also may be new lines within the first parameter and between the first and second.

Thanks for any help you can provide!

christian
  • 2,279
  • 4
  • 31
  • 42

0 Answers0