Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Extract data between brakets

Posted on 2008-06-12
3
Medium Priority
?
322 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 500 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

824 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