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

  • SEARCH
  • Home
  • 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 4625900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:20:23+00:00 2026-05-22T03:20:23+00:00

In a text file I have a file like this: Olivia 7 Sophia 8

  • 0

In a text file I have a file like this:

Olivia
7

Sophia
8

Abigail
9

Elizabeth
10

Chloe
11

Samantha
12

I want to print out all the name only and ignore the numbers.

For some reason, it dont work – it wouldn’t print anything?

<?php
$file_handle = fopen("names.txt", "rb");
while (!feof($file_handle) ) {
  $line_of_text = fgets($file_handle);
  if (!is_numeric((int)$line_of_text)) { 
    echo $line_of_text;
    echo "<br />";
  }
}
fclose($file_handle);
?>
  • 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-05-22T03:20:24+00:00Added an answer on May 22, 2026 at 3:20 am

    You are casting every line with (int). So even lines that are strings will become 0 (zero).

    You can change your code to:

    !is_numeric($line_of_text)
    

    Note: is_numeric() will return true for decimals and scientific notation also. If you are strictly determining if the line contains digits, I suggest ctype_digit()

    UPDATE

    You will also need to trim($line_of_text) as fgets() includes the newline.

    Code inside while():

      $line_of_text = trim(fgets($file_handle));
      if (!ctype_digit($line_of_text)) { 
        echo $line_of_text;
        echo "<br />";
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
Really struggling to work this out... I have a text file with data like
I' ve got a problem with Haskell. I have text file looking like this:
if I have a text file like this : this is line one This
I have a text file like this: A B C And each element has
I have a text file that looks like this. A 102 B 456 C
I have a text file looks like this : 100 50 20 90 4.07498
I have a text file that looks like this: value1 value2 value3 There are
I have a text file on my sdcard filled like this : test1 test2
I have a text file which contains something like this: Hello, my name is

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.