?
Solved

PHP MYSQL: How to select part of string?

Posted on 2008-06-10
8
Medium Priority
?
1,701 Views
Last Modified: 2013-12-13
PHP MySQL


Hello,

How do I code in a PHP script to look for part of a string retrieved from MySQL database?


For example...

MySQL database field contents: (call this $url)
xxxxxxxxx=123.0
xxxxxxxxx=5161163.0
xxxxxxxxx=25523.0
xxxxxxxxx=11.0


I want to extract the value between = and .0
so I get
123
5161163
25523
11


So in PHP, we will have something like

$value = substring of $url

but I don't know how to limit the substring to be between = and .0


0
Comment
Question by:gingera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 24

Assisted Solution

by:glcummins
glcummins earned 800 total points
ID: 21754389
Use the following two lines. At the end, your desired value will be stored in '$value':

list ($xxxxx, $floatNumber) = explode('=', $url);
list ($value, $decimalPortion) = explode('.', $floatNumber);
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 1200 total points
ID: 21754402
You can use a regular expression like

preg_match('/=(.*)\.0/', $url, $m);
$value = $m[1];

echo $value;
0
 
LVL 9

Expert Comment

by:michofreiha
ID: 21754435
strstr($xxxxx, '.0');
0
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 
LVL 19

Expert Comment

by:LordOfPorts
ID: 21754440
Try:

$value = substr($url, strrpos($url, "."));
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 21754485
Correction, ommitted 0 for start:

$value = substr($url, 0, strrpos($url, "."));
0
 

Author Comment

by:gingera
ID: 21755041
Thanks guys!

I have only tried hernst42's suggested solution, and it works for me.

I want to be fair in allocating points  to others who contributed correct solutions but I don't have the time to test out all the other suggestions at the moment.

Could hernst confirm if the other solutions will work?
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21757521
the solution of glummicus should also work, the others not
0
 

Author Closing Comment

by:gingera
ID: 31465899
THANKS!
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 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