Web Analytics Made Easy -
StatCounter Strip all but numbers in a variable - CodingForum

Announcement

Collapse
No announcement yet.

Strip all but numbers in a variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strip all but numbers in a variable

    Hello,

    I have an array I need to strip all but numbers from a value in it. I need to convert ['onote'] to a date... the data is not consistent. Sometimes it is joined 3/3/09. Sometimes its 03/03/2009.. etc.

    PHP Code:
    $new_array array_values($current);
    foreach(
    $new_array as $k => $v){
        foreach (
    $v as $k3 => $v3) {
            if (
    $k3 == 'onote') {
            
    $v3 preg_replace'/[^\d\.]/'''$v3 );
            }
    }
    }
    echo 
    "<pre>";
    print_r($new_array);

    mysql_free_result($result);
    mysql_close();
    ?> 
    If I do:
    PHP Code:
    foreach ($v as $k3 => $v3) {
            if (
    $k3 == 'onote') {
            echo 
    preg_replace'/[^\d\.]/'''$v3 );
            } 
    I get only number but of course only printed not put back into the array.

  • #2
    Originally posted by Hayyel View Post
    Hello,

    I have an array I need to strip all but numbers from a value in it. I need to convert ['onote'] to a date... the data is not consistent. Sometimes it is joined 3/3/09. Sometimes its 03/03/2009.. etc.
    it's a date format? like 04/06/2009?
    try something like this:
    PHP Code:
    $v3 preg_replace("/(\d+)\/(\d+)\/(\d+)/","$1/$2/$3",$v3); 
    best regards

    Comment

    Working...
    X