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 3444272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:53:40+00:00 2026-05-18T08:53:40+00:00

Hey guys and girls, i’m stumped. Trying to get array_search to work with this

  • 0

Hey guys and girls, i’m stumped. Trying to get array_search to work with this script.

 <?php 

$dir = '/var/www/html/pay.group.com/upload';
$i = 0;


if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {

            if ($file != "." && $file != ".."){
            //convert files from pdf to text
            exec("pdftotext /var/www/html/pay.group.com/upload/" . $file . " /var/www/html/tmp/converted/" . $file);
            //create array from text files
            $current_array = file("/var/www/html/tmp/converted/" . $file) or die ("<br/>**cannot find file to create array**"); 
            //search array
            echo array_search('EMPLOYEE NO. ',$current_array);      
            $i++;

            echo var_dump($current_array);
            }
        }
        closedir($dh);

        echo "$i files processed"; 
    }
}


?>

I get nothing from the array_search and I can’t figure out why, its driving me mad.

Here is a relevant part of the var_dump that is working correctly.

"NON NEGOTIABLE " [28]=> string(5) "9871 " [29]=> string(13) "EMPLOYEE NO. " [30]=> string(1) " " [31]=> string(3) "01 " [32]=> string(6) "SHIFT " [33]=> string(1) " " [34]=> string(4) "MIC " [35]=> string(19) "LOCATION HRS/UNITS "

Is there something I am doing wrong? The string for the array search is exactly the same as it is in the actual array so I can’t figure out why its not returning an array index for me.

Using the pre tag, this is what I get.

  [27]=>
  string(15) "NON NEGOTIABLE
"
  [28]=>
  string(5) "9871
"
  [29]=>
  string(13) "EMPLOYEE NO.
"
  [30]=>
  string(1) "
"
  [31]=>
  string(3) "01
"
  [32]=>
  string(6) "SHIFT
"
  [33]=>
  string(1) "
"
  [34]=>
  string(4) "MIC
"
  [35]=>
  string(19) "LOCATION HRS/UNITS
"
  [36]=>
  string(1) "
"
  • 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-18T08:53:41+00:00Added an answer on May 18, 2026 at 8:53 am

    The lines in the uploaded file are on separate lines. file() function leaves the newline characters attached to the array items and this the reason why search does not work.

    You can strip newlines from all array items like this

    array_walk($current_array, 'trim');
    

    After that your search should work.

    Or, as KingCrunch said, use

    file("/var/www/html/tmp/converted/" . $file, FILE_IGNORE_NEW_LINES);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I'm trying to get my head around LINQ and FP, so forgive
Hey guys. I am trying to get the selected option in an each loop.
Hey you guys (and girls), I have implemented the following CSS: #tab-navigation ul li:last-child
Hey guys, a couple of us are looking for a collaborative name to work
Hey guys. I'm trying to configure TFS2010 on a home server. I want to
Hey guys, I've been bashing my head around for hours now, over this login
Hey guys I am trying to implement the twitter for posting the comments about
hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey guys i wrote a quick test. I want delete to call deleteMe which
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also

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.