Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8911325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:54:52+00:00 2026-06-15T03:54:52+00:00

Im using the following code to import a csv that has two columns –

  • 0

Im using the following code to import a csv that has two columns – account & phone:

$csv = array();
$file = fopen('import.csv', 'r');

while (($result = fgetcsv($file)) !== false)
{
    $csv[] = $result;
}

fclose($file);

The results look something like:

Array
(
    [0] => Array
        (
            [0] => 5182334
            [1] => (360) 293-7786
        )

    [1] => Array
        (
            [0] => 8372855
            [1] => (360) 755-3237
        )

    [2] => Array
        (
            [0] => 8373250
            [1] => (360) 873-8853
        )

    [3] => Array
        (
            [0] => 8373226
            [1] => (360) 588-1905
        )
)

What I need to do is loop through the array and clean up the phone numbers removing spaces, parans, etc. I know how to do the clean up but can’t figure out how to loop through the array to do said cleaning.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:54:54+00:00Added an answer on June 15, 2026 at 3:54 am

    You can use array_map and preg_replace for example.

    function clean($item) {
       $item[1] = preg_replace('#[^\d]#', '', $item[1]);
       return $item;
    }
    
    $csv = array_map("clean", $csv);
    

    Or directly in loading phase:

    $csv = array();
    $file = fopen('import.csv', 'r');
    
    while (($result = fgetcsv($file)) !== false)
    {
        $result[1] = preg_replace('#[^\d]#', '', $result[1]);
        $csv[] = $result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that generates a csv file using the following code: header('Content-type:
I am using the following code to import data in Python: one=[] two=[] three=[]
I'm using following Java code for getting data from MySQL table as CSV file.
I noticed the following behavior in the following code (using threading.Timer class): import threading
Using pdfbox displays an error: import java.awt import javax` Based on the following code:
I'm using Eclipse IDE and I have the following line in my code: import
If I create a plot with matplotlib using the following code: import numpy as
Project Euler #10 I am using the following code: import math def is_prime(num): num_sqrt=int(math.sqrt(num))+1
i am using following code in my app: import android.app.Activity; import android.os.Bundle; import android.text.Html;
I am using the following code below: import smtplib import zipfile import tempfile from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.