grab just the cents from string

thevoipman

I want to grab only the cents from the strings I have, not the full dollar.. anything that starts with 0.xx is what I want to echo out:

$paste = "08/29/2014    Interest Paid       $ 0.03  $ 37.69
08/25/2014  ACH Deposit         $ 0.93  $ 37.66
08/20/2014  ACH Deposit         $ 0.63  $ 36.73
08/04/2014  ACH Deposit         $ 0.95  $ 36.10
08/04/2014  ACH Deposit         $ 0.57  $ 35.15
08/04/2014  ACH Deposit         $ 0.88  $ 34.58
07/31/2014  Interest Paid       $ 0.01  $ 33.70
07/31/2014  ACH Deposit         $ 0.13  $ 33.69
07/31/2014  ACH Deposit         $ 0.96  $ 33.56
07/31/2014  ACH Deposit         $ 0.65  $ 32.60
07/31/2014  ACH Deposit         $ 0.53  $ 31.95
07/31/2014  ACH Deposit         $ 0.83  $ 31.42
07/30/2014  ACH Deposit         $ 0.63  $ 30.59
07/28/2014  ACH Deposit         $ 0.76  $ 29.96";

I have tried the following but it wouldn't do what I need it nor echo line by line of the cents i'm looking for...

$find = strpos($paste, '0.');
sscanf(substr($paste, $find), '0.%d', $numbers);

Any help I can get on this is greatly appreciated. Thank you in advance..

hex494D49

You could try something like this

$paste = <<<EOT
08/29/2014  Interest Paid       $ 0.03  $ 37.69
08/25/2014  ACH Deposit         $ 0.93  $ 37.66
08/20/2014  ACH Deposit         $ 0.63  $ 36.73
08/04/2014  ACH Deposit         $ 0.95  $ 36.10
08/04/2014  ACH Deposit         $ 0.57  $ 35.15
08/04/2014  ACH Deposit         $ 0.88  $ 34.58
07/31/2014  Interest Paid       $ 0.01  $ 33.70
07/31/2014  ACH Deposit         $ 0.13  $ 33.69
07/31/2014  ACH Deposit         $ 0.96  $ 33.56
07/31/2014  ACH Deposit         $ 0.65  $ 32.60 07/31/2014  ACH Deposit         $ 0.53  $ 31.95
07/31/2014  ACH Deposit         $ 0.83  $ 31.42
07/30/2014  ACH Deposit         $ 0.63  $ 30.59
07/28/2014  ACH Deposit         $ 0.76  $ 29.96
EOT;

preg_match_all('/\$\s00?\.(\d+)/', $paste, $cents);
print_r($cents[1]);

As you can see, each value doesn't have to be in each line.

Output:

Array
(
    [0] => 03
    [1] => 93
    [2] => 63
    [3] => 95
    [4] => 57
    [5] => 88
    [6] => 01
    [7] => 13
    [8] => 96
    [9] => 65
    [10] => 53
    [11] => 83
    [12] => 63
    [13] => 76
)

If you want to have the whole value like 0.03 change the pattern above to this.

\$\s(00?\.\d+)

Working PHP demo | Working Regex demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

grab just the cents from string

From Dev

Grab Amount from Specific String

From Dev

What is the best method to obtain dollar value with cents from a string?

From Dev

Superscript cents in an attributed string

From Dev

MYSQL and PHP loop and grab just one item from a joint table?

From Dev

Git Log Pretty Format - Grab just a number from the title

From Dev

Best way to grab a specific position from a string

From Dev

Grab random sequence of words from a string?

From Dev

grab value from string in reverse order

From Dev

regex to grab from char/string to another

From Dev

How to grab text from a messy string in java?

From Dev

Best way to grab a specific position from a string

From Dev

Regex to grab the data from an address string

From Dev

How to Grab a String from This to That from a Webpage's Source?

From Dev

VBA Regex - Grab Hour HH:MM from String

From Dev

How to grab URL from string with specified alt tags

From Dev

How to grab ObjectId from object in parse and present it as string in swift

From Dev

Grab and pass dict/JSON associated with string from list

From Dev

How to grab URL from string with specified alt tags

From Dev

Grab the last executed command from history as a string and store in variable in bash

From Dev

Regex from a html parsing, how do I grab a specific string?

From Dev

Can't grab string from URL with special characters

From Dev

Using Grep -o or Sed/Awk to Grab Snippet from Middle of String

From Dev

How can I grab a group of words from a string?

From Dev

How to grab values from unformatted string in ios objective-c?

From Dev

Ruby: Convert dollar (String) to cents (Integer)

From Dev

Wrap all cents values in a string with superscript

From Dev

Send just a string from $.ajax to c#

From Dev

Extract just file path from string

Related Related

  1. 1

    grab just the cents from string

  2. 2

    Grab Amount from Specific String

  3. 3

    What is the best method to obtain dollar value with cents from a string?

  4. 4

    Superscript cents in an attributed string

  5. 5

    MYSQL and PHP loop and grab just one item from a joint table?

  6. 6

    Git Log Pretty Format - Grab just a number from the title

  7. 7

    Best way to grab a specific position from a string

  8. 8

    Grab random sequence of words from a string?

  9. 9

    grab value from string in reverse order

  10. 10

    regex to grab from char/string to another

  11. 11

    How to grab text from a messy string in java?

  12. 12

    Best way to grab a specific position from a string

  13. 13

    Regex to grab the data from an address string

  14. 14

    How to Grab a String from This to That from a Webpage's Source?

  15. 15

    VBA Regex - Grab Hour HH:MM from String

  16. 16

    How to grab URL from string with specified alt tags

  17. 17

    How to grab ObjectId from object in parse and present it as string in swift

  18. 18

    Grab and pass dict/JSON associated with string from list

  19. 19

    How to grab URL from string with specified alt tags

  20. 20

    Grab the last executed command from history as a string and store in variable in bash

  21. 21

    Regex from a html parsing, how do I grab a specific string?

  22. 22

    Can't grab string from URL with special characters

  23. 23

    Using Grep -o or Sed/Awk to Grab Snippet from Middle of String

  24. 24

    How can I grab a group of words from a string?

  25. 25

    How to grab values from unformatted string in ios objective-c?

  26. 26

    Ruby: Convert dollar (String) to cents (Integer)

  27. 27

    Wrap all cents values in a string with superscript

  28. 28

    Send just a string from $.ajax to c#

  29. 29

    Extract just file path from string

HotTag

Archive