Hi all,
I have an array called html which contains rows of text.
E.g:

$html[0] = 1 Full, Gen. 3 TMSWK2D 9 Poor write quality 
$html[1] = 2 Full, Gen. 1 TMSWK2C  Read Only, Clean Tape

How would I go about taking each array value and splitting the row of text into individual values?
E.g:

$newArr[0][1] = 1
$newArr[1][1] = Full
$newArr[2][1] = Gen.
$newArr[3][1] = 3
$newArr[4][1] = TMSWK2D
$newArr[5][1] = 9
$newArr[6][1] = Poor write quality

$newArr[0][2] = 2
$newArr[1][2] = Full
$newArr[2][2] = Gen.
$newArr[3][2] = 1
$newArr[4][2] = TMSWK2C
$newArr[5][2] = 9
$newArr[6][2] = Read Only, Clean Tape

OKay, I've attempted to use the explode() function, but am not getting correct results.

$i=0;
	$x=0;
	while(isset($html[$i]))
	{
		echo "<table>";
		echo "<tr><td>". $html[$i] ."</td></tr>";
		echo "</table>";

		$newArr = explode(" ", $html[$i]);    //use space as the delimeter
		while(isset($newArr[$x]))
		{
			echo $newArr[$x] ."<br>";
			$x++;
		}	
		$i++;
	}

I would expect to see:

1 
Full, 
Gen.
3  
TMSWK2D 
9 
Poor write quality

But instead, I get:

1 Â Full, Gen. 3 Â  TMSWK2D 9 Â  Poor write quality 
1







 Full,
Gen.
3







 






TMSWK2D



9











 
Poor
write
quality

With lots of line breaks in between each $newArr value... It's good but it's not right! Can anyone lend me some help!?

Hi friend,

Your job is done. be happy :)

<?php

$html[0] = " 1 Full, Gen. 3 TMSWK2D 9 Poor write quality"; 
$html[1] = "2 Full, Gen. 1 TMSWK2C  Read Only, Clean Tape";


$take =preg_split("/\ /", $html[0]);
for($n=0;$n<count($take);$n++){ 
print($take[$n]);
echo "<br/>";
}

?>

Just cut and paste.
 Explore ;)

Hey Richieking! Thankyou for your help. Your code would work a charm if the content of my $html array was as simple as it looked! In fact, the reason why I was getting so many line breaks was because the values of the $html array had un-consistent spacing. (I used the DOMDocument method to formulate the array). When I did a view source on the retrieved data, I got something like:

1           Â Full, Gen. 3          Â          TMSWK2D    9            Â  Poor write quality

So some parts of the value had 11 spaces, and others had just one. Therefore it is completely impractical to try and code around this. Instead, I will go back to the DOMDocument and see if there is a way of returning more consistent data.

Anyhow, how can I get rid of/convert the "Â" character when printing out the row? I tried htmlentities() but that didn't seem to work.
chrz

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.