We help IT Professionals succeed at work.
Get Started

PHP an removing whitespaces

dogsareit asked
Last Modified: 2020-01-19
I am extracting data from a pdf and so far, it's has been going fairly decent. I am working in localhost, Win 10, WampServer and using PHP 5.6.25.
I am using PdfParser and used composer to install it. It was successful. I am trying to explode a line of data on whitespace and it simple will not do it. I have done this before without a problem. I know from experience, that what I view in I.E. - source view - may not be what it really is to me visually. They appear to be a whitespace(s), so I decided that I would count the number of whitespaces in order to create the correct length for exploding on properly, and it returns a count of zero. I have tried to replace the whitespace(s) with another character - * - and it will not do it. I have even tried using chr(32) to represent the whitespace(s).
Therefore, even though it "looks" like a whitespace, maybe it really isn't. But I have no clue as to what it is or how to resolve it.
Can someone guide/educate me about what to try next or how to resolve this ??
I have other lines of data that I will need to explode based on whitespaces in this project.
Below is the snippet of coding: I have also attached a snapshot of what it looks in the source pane of I.E.
	if ($strtype == 'account')
			// look for actnbr
                       $wrkBegChar = 'AccountNumber';
	               $wrkEndChar = 'USD';
	     	       $strBegPos = stripos($strSearchData , $wrkBegChar,1); 
	    	       $strEndPos = stripos($strSearchData, $wrkEndChar, $strBegPos); 
		       $strLen = (($strEndPos +6) - ($strBegPos + 17));
	    	       $strWork = trim(substr($strSearchData ,($strBegPos + 17), $strLen));
		       $strWork = trim(substr($strSearchData ,($strBegPos + 17), $strLen));
			echo '<BR><BR>$strWork...' . $strWork . '<BR><BR>';
			// count the nbr of whitespaces
			$wrkBlanks = '';
			$wrkCount = 0;
			$wrkCount = substr_count($strWork,' ');
			echo "nbr of blanks.. " . $wrkCount;
			for ($x = 0; $x <= $wrkCount; $x++) 
			        	$wrkBlank = ($wrkBlanks . ' ');
			$wrkArray = explode($wrkBlanks,$strWork);
			$wrkCnt = count($wrkArray);
                        echo '<BR>Array Count ' . $wrkCnt;
		        foreach($wrkArray as $key => $value)
                                echo 'Line values   ' . $key." has the value ". $value . '<BR><BR>';
			//$stripData = trim($wrkArray[1]);

Open in new window

Watch Question
Most Valuable Expert 2018
Distinguished Expert 2019
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE