1

I have a little PHP script I am running.
It basically puts the content of an XML file and assigns it to a variable.
I then create an array containing all the XML tags and values I want to use, using the parse array function from LIB_parse.php:

function parse_array($string, $beg_tag, $close_tag)
{
    preg_match_all("($beg_tag(.*)$close_tag)siU", $string, $matching_data);
        //preg_match_all("($beg_tag(.*)($beg_tag(.*)$close_tag)+(.*)$close_tag)siU", $string, $matching_data);
    return $matching_data[0];
}

This all works well.

But what I would like to do is remove all duplicates from this now huge array.
I have done it through Excel and I know it should give me 3945 XML tags and values.
But when I run the array through array_unique, it returns me an array with 3945 lines but only about 400 of them actually contain the XML tags and values I want, the others are blank lines.

$value = file_get_contents("myXMLfile.xml");
$array = parse_array($value, "<marker", "/>");
$clean_array = array_unique($array);

I then use a loop to put the values of the array into another XML file.

Any ideas?

Sorry the length of this.

Brilliand
  • 13,404
  • 6
  • 46
  • 58
MyGodAL3X
  • 11
  • 1
  • 1
    What does `parse_array` do? – Brilliand Jul 31 '13 at 19:38
  • Okay, I found the parse_array function and edited it into the question. – Brilliand Jul 31 '13 at 19:41
  • Creates an array from all the strings that match the criteria given in the call. So in this case it creates an array, in which each entry is a string starting with that is found in $value. – MyGodAL3X Jul 31 '13 at 19:42
  • Could the tags simply be displaying wrong in your web browser? Check View Source, if you're looking at the results in your browser. – Brilliand Jul 31 '13 at 19:47
  • I don't look at the resulting file through a browser. I put the results in an XML file. There are certain tags and values that appear as expected (about 400) but all the other lines in the file are blank (like putting \n). – MyGodAL3X Jul 31 '13 at 19:57
  • And if I don't use the array_unique function I can export the $array array and get the 39000 XML tags and values all displaying correctly – MyGodAL3X Jul 31 '13 at 19:58
  • 2
    I think it's a good idea to create a small test case with 2 to 4 lines of XML, and then dump the content that you get from `parse_array()` and analyze the result. It might not be what you think it is - and nobody else can recreate your case because you haven't given any sample data. – Sven Jul 31 '13 at 20:27
  • I will give it a shot with a smaller sample, and if I get nothing I will post samples here tomorrow. – MyGodAL3X Jul 31 '13 at 21:38

0 Answers0