Extract word after a keyword

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
khamani
Forum Newbie
Posts: 1
Joined: Mon Nov 01, 2010 2:16 am

Extract word after a keyword

Post by khamani »

Hi,
I would like to extract the figures from a string. The string is MYR1,200. I want to extract the 1,200. Also the figures can be three e.g MYR800. So I want to extract the figure regardless of whether they are 3 or 4. kindly assist

Thanks
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Extract word after a keyword

Post by s.dot »

Code: Select all

$string = 'MYR5483';
echo substr($string, 3);
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Extract word after a keyword

Post by VladSun »

Code: Select all

preg_match('#\D+(\d+,?\d+)#', $input, $match)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply