|
Posted by mik3l3374 on 11/10/07 17:30
On Nov 9, 3:41 am, "otrWal...@gmail.com" <otrWal...@gmail.com> wrote:
> Note: $code is a single line of code that the previous segment of this
> method has located.
>
> I have this...
>
> preg_match('/\bnew wBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches);
> $results = $arrMatches[1];
>
> it will find this...
>
> new wBug ( $myvar ); // <-- this is what $code contains
>
> and it will give me...
>
> $myvar
>
> Which is exactly what I want, for this instance, but if I have this...
>
> new wBug ( $myvar, true ); // <-- this is what $code contains,
> this time
>
> I get this...
>
> $myvar, true
>
> I'd like to only get....
>
> $myvar
>
> Actually, I'd like to get each parameter in its own array element of
> '$arrMatches'
>
> My RegExp is limited on this one.
>
> Can someone throw me a bone?
>
> Thx
>
> walter
how about this, no regexp, just simple sub strings
$string = 'new wBug ( $myvar , true )';
$firstpos = strpos($string,"(");
$lastpos = strrpos($string,")");
$str=substr($string,$firstpos+1,$lastpos-$firstpos-1);
if ( strstr($str,",") )
{
$var=explode(",",$str);
echo $var[0];
}
else
{
echo "$str\n";
}
Navigation:
[Reply to this message]
|