Solved

PHP MYSQL: How to select part of string?

Posted on 2008-06-10
8
1,699 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 200 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 300 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

717 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