Parsing String

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mist3r0
Forum Newbie
Posts: 1
Joined: Tue Feb 02, 2010 8:22 am

Parsing String

Post by mist3r0 »

Hello boys, I've need help,

I've this file xml:

Code: Select all

 
{{Calciatore in rosa|n°=1|nazione=Brasile|nome=[[Dida]]|ruolo=P}}
{{Calciatore in rosa|n°=32|nazione=Brasile|nome=[[Dida2]]|ruolo=P}}
{{Calciatore in rosa|n°=54|nazione=Brasile|nome=[[Dida3]]|ruolo=P}}
{{Calciatore in rosa|n°=3|nazione=Brasile|nome=[[Dida4]]|ruolo=P}}
{{Calciatore in rosa|n°=6|nazione=Brasile|nome=[[Dida5]]|ruolo=P}}
{{Calciatore in rosa|n°=7|nazione=Brasile|nome=[[Dida6]]|ruolo=P}}
{{Calciatore in rosa|n°=10|nazione=Brasile|nome=[[Dida7]]|ruolo=P}}
{{Calciatore in rosa|n°=11|nazione=Brasile|nome=[[Dida8]]|ruolo=P}}
{{Calciatore in rosa|n°=16|nazione=Brasile|nome=[[Dida9]]|ruolo=P}}
 
I need to get the number (n=1) and the name (nome=Dida) of all row, how I can do it? :banghead:

can you help me? thanks
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Parsing String

Post by AbraCadaver »

Because I'm bored, here's one simplistic way if this structure will be consistent:

Code: Select all

$lines = file('yourfile.xml');
 
foreach($lines as $line) {
    $line = explode('|', $lines);
    $no[] = $line[1];
    $nome[] = $line[3];
}
If this is only a snippet, and you really have a valid XML file, then this may or may not work.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply