Solved

Extract data between brakets

Posted on 2008-06-12
3
315 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
Comment Utility

<?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
Comment Utility
<?
$string = '10K White Gold(+100)';

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

echo $result;
?>
0
 

Author Closing Comment

by:dougbnv
Comment Utility
Perfect thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

744 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

15 Experts available now in Live!

Get 1:1 Help Now