Solved

Extract data between brakets

Posted on 2008-06-12
3
318 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

820 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