gingera
asked on
PHP MYSQL: How to select part of string?
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
strstr($xxxxx, '.0');
Try:
$value = substr($url, strrpos($url, "."));
$value = substr($url, strrpos($url, "."));
Correction, ommitted 0 for start:
$value = substr($url, 0, strrpos($url, "."));
$value = substr($url, 0, strrpos($url, "."));
ASKER
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?
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?
the solution of glummicus should also work, the others not
ASKER
THANKS!