Urinary tract infection (UTI) is a common type of infectious disease globally. The aim of this study was to detect the frequency of fosA3 and fosC2 genes in extended-spectrum β-lactamases (ESBL) and bla, bla, and bla genes in AmpC β-lactamases-producing isolates of Escherichia coli. In total, 120 isolates of E. coli were collected from three teaching hospitals between March 2014 and February 2015. Antibiotic susceptibility tests were carried out by disk diffusion method. The presence of bla, bla, bla, fosA3, and fosC2 genes was detected by polymerase chain reaction (PCR) and sequencing. Of the 120 strains, 92 (76.6%) were identified as ESBL producers, 30 (25%) were determined as AmpC β-lactamase producers, and 24 (20%) had both ESBL and AmpC β-lactamase enzymes. Imipenem, fosfomycin, and nitrofurantoin had the best effect against isolates of E. coli. PCR assay demonstrated that the frequency of bla, bla, and bla genes among AmpC β-lactamases-producing strains were 39%, 1%, and 17.5%, respectively. This study reports the first detection of fosfomycin resistance in Iran. This study indicated the increasing prevalence of UTI isolates of E. coli-harboring ESBL and AmpC β-lactamases genes in Iran. Therefore, due to the high rate of bla and bla genes and emergence of fosfomycin-resistant E. coli isolates, we recommend continuous monitoring of antibiotic resistance as well as attention to guidelines of infection controls.