Solved

Extract data between brakets

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

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

$result = +100
0
Comment
Question by:dougbnv
3 Comments
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 125 total points
ID: 21771063

<?PHP

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

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

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

$len = $last-$first-1;

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

echo $result.'<br>';
 

//or
 

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

echo $result;

?>

Open in new window

0
 
LVL 2

Expert Comment

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

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

echo $result;
?>
0
 

Author Closing Comment

by:dougbnv
ID: 31466595
Perfect thanks!
0

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 (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  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