Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Bagaimana parse item di XML dengan preg_match di PHP?

Saya punya file XML RSS 2 seperti ini:

.............

<item>

<title>Judul 1</title>

<link>http://host/file1%3C/link%3E

<description>...</description>

<pubDate>Mon, 10 Mar 2008 20:48:04 +0700</pubDate>

</item>

<item>

<title>Judul 2</title>

<link>http://host/file1%3C/link%3E

<description> :s :s ...</description>

<pubDate>Sat, 15 Mar 2008 04:37:32 +0700</pubDate>

</item>

..........

Trus saya coba menggunakan fungsi preg_match seperti ini:

"preg_match( '/(<item>.*<\/item>)/s' , $content, $matches);"

Fungsi pregmatch diatas menghasilkan $matches[0] berisi semua item sampai habis.

Yang saya inginkan $matches berisi data peritem <item>...</item>. Misalnya: $matches[0] = ...item pertama...; $matches[1] = .... item kedua, dst. jadi bisa diiterate pakai foreach tanpa fungsi explode lagi.

Bisa gak? kalo bisa bantuin regex-nya dong...!

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    sepertinya agak sulit, coba kamu ajukan pertanyaan kamu ke www.ilmukonputer.com

    disitu ada pakarnya.

Still have questions? Get your answers by asking now.