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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:44:53+00:00 2026-06-11T16:44:53+00:00

I have a long xml data file with 500+ items in it, it comes

  • 0

I have a long xml data file with 500+ items in it, it comes in this form:

<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<ITEM>
    <TITLE>ITEM name</TITLE>
    <TYPE>"T1", "T2", "T3" </TYPE>
    <DESCIPTION>DESCIPTIONiliate Page CPM</DESCIPTION>
    <PRICE>PRICE</PRICE>
    <ITEM>http://mysite.com/item-link</ITEM>
</ITEM>
</CATALOG>

and I use the following code in the php page to import data from the xml file:

<?php
$ITEMSS = new SimpleXMLElement('ITEMS.xml', null, true);

echo <<<EOF
<table width="100%" align="center" border="1" bordercolor="#0099ff" cellpadding="1" cellspacing="0">

    <tr>
            <th bgcolor="#66ccff"><span class="style4">ITEM Name</span></th>
            <th bgcolor="#66ccff"><span class="style4">item TYPE </span></th>
            <th bgcolor="#66ccff"><span class="style4">item DESCIPTION </span></th>
            <th bgcolor="#66ccff"><span class="style4">item PRICE</span></th>
            <th bgcolor="#66ccff"><span class="style4">link to item</span></th>
    </tr>

EOF;
foreach($ITEMSS as $ITEMS) // loop through our DATAS
{
    echo <<<EOF
    <tr height="30" align=middle>
            <td><a href="{$ITEMS->ITEM}" target="_blank"><span class="STYLE7">{$ITEMS->TITLE}</span></a></td>
            <td><span class="STYLE8">{$ITEMS->TYPE}</span></td>
            <td><span class="STYLE8">{$ITEMS->DESCIPTION}</span></td>
            <td><span class="STYLE8">{$ITEMS->PRICE}</span></td>
            <td><a href="{$ITEMS->ITEM}" target="_blank"><B><span class="STYLE7">cHECK IT OUT</span></B></a></td>
    </tr>

EOF;
}
echo '</table>';
?>

in the TYPE I have different values like:

    <TYPE>"T1", "T2", "T3" </TYPE>
    <TYPE>"T1", "T4", "T6" </TYPE>
    <TYPE>"T1", "T8", "T1" </TYPE>

each item may have diffrent TYPE values

I need to add an “if” statement in the loop to select only some data if a value is in array of TYPE somethink like:

foreach($ITEMSS as $ITEMS) // loop through our DATAS
{
$options = array($ITEMS->TYPE);

if (in_array("T1", $options))

   { echo <<<EOF
    <tr height="30" align=middle>
            <td><a href="{$ITEMS->ITEM}" target="_blank"><span class="STYLE7">{$ITEMS->TITLE}</span></a></td>
            <td><span class="STYLE8">{$ITEMS->TYPE}</span></td>
            <td><span class="STYLE8">{$ITEMS->DESCIPTION}</span></td>
            <td><span class="STYLE8">{$ITEMS->PRICE}</span></td>
            <td><a href="{$ITEMS->ITEM}" target="_blank"><B><span class="STYLE7">cHECK IT OUT</span></B></a></td>
    </tr>


EOF;
}

}

but even if the value I look for is in the array , it shows nothing!.

So how can I use if in array statement in this case?

  • 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-06-11T16:44:54+00:00Added an answer on June 11, 2026 at 4:44 pm

    The problem comes from your preparation of the $options variable, try initiating it like so;

    PHP >= 5.3

    $options = array_map(function($type) {
        return str_replace('"', '', trim($type));
    }, explode(',', $ITEMS->TYPE));
    

    PHP < 5.3 (put the function out of the loop :D)

    function parseTypes($type) {
        return str_replace('"', '', trim($type));
    }
    
    $options = array_map(parseTypes, explode(',', $ITEMS->TYPE));
    

    That should explode the types into an array, remove the quotes and trim extra spaces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long xml data file with 500+ items in it, it comes
I have a long xml file the content of the file are below: <?xml
Has anyone had this problem? My projects tend to have some long XML files
I have an XML file that is very long, but here is a shot
I have an option to choose between local based data storing (xml file) or
I currently have an iPhone app that reads data from an external XML file
I have this very huge XML file of size 2.8GB. This is Polish Wikipedia's
I have an XML file that is pretty long. Below is the code I
I have an xml file with the following data: <BOOKS> <BOOK> <TITLE image=./images/govnahDesign.jpg>Bible</TITLE> <CATEGORY>Book</CATEGORY>
How long have the MySQL XML functions like ExtractValue() and UpdateXML() been supported? A

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.