0
$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.

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.