Extract data between brakets

Posted on 2008-06-12
Last Modified: 2013-12-13
I want to remove the data between brackets in php like:

$string = 10K White Gold(+100);

$result = +100
Question by:dougbnv
LVL 29

Accepted Solution

rdivilbiss earned 125 total points
ID: 21771063


$string = "10K White Gold(+100)";

$first = strpos($string,'(');

$last = strrpos($string,')');

$len = $last-$first-1;

$result = substr($string,$first+1,$len);

echo $result.'<br>';


$result = substr($string,strpos($string,'(')+1,strrpos($string,')')-strpos($string,'(')-1);

echo $result;


Open in new window


Expert Comment

ID: 21771502
$string = '10K White Gold(+100)';

$result = substr($string, strpos($string, "(")+1, strpos($string, ")") - (strpos($string, "(")+1));

echo $result;

Author Closing Comment

ID: 31466595
Perfect thanks!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now