PHP: Get function argument with preg_match_all

3

Good afternoon:

I'm picking up the value of calls to a particular PHP function straight from the source code.

What I need is to scan each of the lines of the source code, and if there are one or more altext () function calls, get the argument passed. For example:

<img alt="<?php echo altext('[Este é um texto alternativo]');?>">

In the example case, I need to be returned only "This is alternate text" (without quotes). The [] were placed to avoid that, if there is a ') in the middle of the text, the search stops before the end. I'm trying to use preg_match_all("/\[altext\]\(\'\[(.*)\]\'\)/", $data, $matches); but it's not returning anything. $data is the line of code I'm looking for from the source code with fgets .

    
asked by anonymous 19.06.2015 / 20:18

2 answers

1

I was able to read a text from Martin Streicher and < a href="http://php.net/manual/en/regexp.reference.meta.php"> PHP Manual

preg_match_all("/altext\(\'(.*)\'\)/", $data, $matches);

And it does not require any other artifice if a ') appears in the middle of the argument.

I do not believe it was that easy. I looked for days.

    
19.06.2015 / 20:52
0

I've emailed Everton.

$re = "/(\W|^)este é um texto alternativo(\W|$)/"; 
preg_match_all($re, $data, $matches);

print_r($matches)
    
19.06.2015 / 20:29