tags:

views:

34

answers:

1
$var = 'Click on this <a href="#">link</a>. (goes to heaven) (and then somewhere else)';

How to get the text, which is placed between first brackets?

Throw its value to $extra

In this example $extra = 'goes to heaven'

Thanks.

+2  A: 
preg_match("/\\((.+?)\\)/", $var, $matches);
$extra = $matches[1];

This is strictly true for the example you provided. If you are parsing arbitrary HTML, you'll have to use DOMDocument or similar instead.

Artefacto
no $var = before preg_match?
Happy
@Ignatz Sure, I admitted `$var` was already set.
Artefacto