EPG PHP script

epgscript

EPG stands for Electronic Program Guide. It is a feature that is available on many TVs and other devices that allows you to view a list of the current and upcoming programs that are available on a particular TV channel or network. The EPG typically includes information such as the name of the program, the time it is scheduled to air, and a brief description of the program. It can be accessed through the TV’s menu or by pressing a dedicated button on the remote control. The EPG can be a useful tool for finding and scheduling your favorite shows and for discovering new programs that you may be interested in.

The script extract the data from the below links:

Country Channels EPG
🇦🇫 Afghanistan 68 https://iptv-org.github.io/epg/guides/af.xml
🇦🇱 Albania 93 https://iptv-org.github.io/epg/guides/al.xml
🇩🇿 Algeria 124 https://iptv-org.github.io/epg/guides/dz.xml
🇦🇸 American Samoa 62 https://iptv-org.github.io/epg/guides/as.xml
🇦🇩 Andorra 83 https://iptv-org.github.io/epg/guides/ad.xml
🇦🇴 Angola 118 https://iptv-org.github.io/epg/guides/ao.xml
🇦🇮 Anguilla 63 https://iptv-org.github.io/epg/guides/ai.xml
🇦🇶 Antarctica 51 https://iptv-org.github.io/epg/guides/aq.xml
🇦🇬 Antigua and Barbuda 63 https://iptv-org.github.io/epg/guides/ag.xml
🇦🇷 Argentina 273 https://iptv-org.github.io/epg/guides/ar.xml
🇦🇲 Armenia 99 https://iptv-org.github.io/epg/guides/am.xml
🇦🇼 Aruba 67 https://iptv-org.github.io/epg/guides/aw.xml
🇦🇺 Australia 166 https://iptv-org.github.io/epg/guides/au.xml
🇦🇹 Austria 147 https://iptv-org.github.io/epg/guides/at.xml
🇦🇿 Azerbaijan 98 https://iptv-org.github.io/epg/guides/az.xml
🇧🇸 Bahamas 71 https://iptv-org.github.io/epg/guides/bs.xml
🇧🇭 Bahrain 99 https://iptv-org.github.io/epg/guides/bh.xml
🇧🇩 Bangladesh 72 https://iptv-org.github.io/epg/guides/bd.xml
🇧🇧 Barbados 69 https://iptv-org.github.io/epg/guides/bb.xml
🇧🇾 Belarus 112 https://iptv-org.github.io/epg/guides/by.xml
🇧🇪 Belgium 175 https://iptv-org.github.io/epg/guides/be.xml
🇧🇿 Belize 87 https://iptv-org.github.io/epg/guides/bz.xml
🇧🇯 Benin 112 https://iptv-org.github.io/epg/guides/bj.xml
🇧🇲 Bermuda 57 https://iptv-org.github.io/epg/guides/bm.xml
🇧🇹 Bhutan 69 https://iptv-org.github.io/epg/guides/bt.xml
🇧🇴 Bolivia 206 https://iptv-org.github.io/epg/guides/bo.xml
🇧🇶 Bonaire 55 https://iptv-org.github.io/epg/guides/bq.xml
🇧🇦 Bosnia and Herzegovina 122 https://iptv-org.github.io/epg/guides/ba.xml
🇧🇼 Botswana 102 https://iptv-org.github.io/epg/guides/bw.xml
🇧🇻 Bouvet Island 53 https://iptv-org.github.io/epg/guides/bv.xml
🇧🇷 Brazil 304 https://iptv-org.github.io/epg/guides/br.xml
🇮🇴 British Indian Ocean Territory 51 https://iptv-org.github.io/epg/guides/io.xml
🇻🇬 British Virgin Islands 63 https://iptv-org.github.io/epg/guides/vg.xml
🇧🇳 Brunei 100 https://iptv-org.github.io/epg/guides/bn.xml
🇧🇬 Bulgaria 153 https://iptv-org.github.io/epg/guides/bg.xml
🇧🇫 Burkina Faso 117 https://iptv-org.github.io/epg/guides/bf.xml
🇧🇮 Burundi 108 https://iptv-org.github.io/epg/guides/bi.xml
🇰🇭 Cambodia 97 https://iptv-org.github.io/epg/guides/kh.xml
🇨🇲 Cameroon 118 https://iptv-org.github.io/epg/guides/cm.xml
🇨🇦 Canada 274 https://iptv-org.github.io/epg/guides/ca.xml
🇨🇻 Cape Verde 111 https://iptv-org.github.io/epg/guides/cv.xml
🇰🇾 Cayman Islands 63 https://iptv-org.github.io/epg/guides/ky.xml
🇨🇫 Central African Republic 107 https://iptv-org.github.io/epg/guides/cf.xml
🇹🇩 Chad 110 https://iptv-org.github.io/epg/guides/td.xml
🇨🇱 Chile 235 https://iptv-org.github.io/epg/guides/cl.xml
🇨🇳 China 182 https://iptv-org.github.io/epg/guides/cn.xml
🇨🇽 Christmas Island 51 https://iptv-org.github.io/epg/guides/cx.xml
🇨🇨 Cocos (Keeling) Islands 51 https://iptv-org.github.io/epg/guides/cc.xml
🇨🇴 Colombia 226 https://iptv-org.github.io/epg/guides/co.xml
🇰🇲 Comoros 128 https://iptv-org.github.io/epg/guides/km.xml
🇨🇰 Cook Islands 62 https://iptv-org.github.io/epg/guides/ck.xml
🇨🇷 Costa Rica 199 https://iptv-org.github.io/epg/guides/cr.xml
🇭🇷 Croatia 141 https://iptv-org.github.io/epg/guides/hr.xml
🇨🇺 Cuba 198 https://iptv-org.github.io/epg/guides/cu.xml
🇨🇼 Curacao 67 https://iptv-org.github.io/epg/guides/cw.xml
🇨🇾 Cyprus 124 https://iptv-org.github.io/epg/guides/cy.xml
🇨🇿 Czech Republic 198 https://iptv-org.github.io/epg/guides/cz.xml
🇨🇩 Democratic Republic of the Congo 119 https://iptv-org.github.io/epg/guides/cd.xml
🇩🇰 Denmark 112 https://iptv-org.github.io/epg/guides/dk.xml
🇩🇯 Djibouti 135 https://iptv-org.github.io/epg/guides/dj.xml
🇩🇲 Dominica 63 https://iptv-org.github.io/epg/guides/dm.xml
🇩🇴 Dominican Republic 203 https://iptv-org.github.io/epg/guides/do.xml
🇹🇱 East Timor 101 https://iptv-org.github.io/epg/guides/tl.xml
🇪🇨 Ecuador 201 https://iptv-org.github.io/epg/guides/ec.xml
🇪🇬 Egypt 164 https://iptv-org.github.io/epg/guides/eg.xml
🇸🇻 El Salvador 202 https://iptv-org.github.io/epg/guides/sv.xml
🇬🇶 Equatorial Guinea 122 https://iptv-org.github.io/epg/guides/gq.xml
🇪🇷 Eritrea 100 https://iptv-org.github.io/epg/guides/er.xml
🇪🇪 Estonia 112 https://iptv-org.github.io/epg/guides/ee.xml
🇪🇹 Ethiopia 111 https://iptv-org.github.io/epg/guides/et.xml
🇫🇰 Falkland Islands 53 https://iptv-org.github.io/epg/guides/fk.xml
🇫🇴 Faroe Islands 56 https://iptv-org.github.io/epg/guides/fo.xml
🇫🇯 Fiji 62 https://iptv-org.github.io/epg/guides/fj.xml
🇫🇮 Finland 123 https://iptv-org.github.io/epg/guides/fi.xml
🇫🇷 France 351 https://iptv-org.github.io/epg/guides/fr.xml
🇬🇫 French Guiana 69 https://iptv-org.github.io/epg/guides/gf.xml
🇵🇫 French Polynesia 65 https://iptv-org.github.io/epg/guides/pf.xml
🇹🇫 French Southern Territories 98 https://iptv-org.github.io/epg/guides/tf.xml
🇬🇦 Gabon 111 https://iptv-org.github.io/epg/guides/ga.xml
🇬🇲 Gambia 100 https://iptv-org.github.io/epg/guides/gm.xml
🇬🇪 Georgia 119 https://iptv-org.github.io/epg/guides/ge.xml
🇩🇪 Germany 272 https://iptv-org.github.io/epg/guides/de.xml
🇬🇭 Ghana 110 https://iptv-org.github.io/epg/guides/gh.xml
🇬🇮 Gibraltar 51 https://iptv-org.github.io/epg/guides/gi.xml
🇬🇷 Greece 159 https://iptv-org.github.io/epg/guides/gr.xml
🇬🇱 Greenland 60 https://iptv-org.github.io/epg/guides/gl.xml
🇬🇩 Grenada 63 https://iptv-org.github.io/epg/guides/gd.xml
🇬🇵 Guadeloupe 80 https://iptv-org.github.io/epg/guides/gp.xml
🇬🇺 Guam 69 https://iptv-org.github.io/epg/guides/gu.xml
🇬🇹 Guatemala 201 https://iptv-org.github.io/epg/guides/gt.xml
🇬🇬 Guernsey 53 https://iptv-org.github.io/epg/guides/gg.xml
🇬🇳 Guinea 113 https://iptv-org.github.io/epg/guides/gn.xml
🇬🇼 Guinea-Bissau 107 https://iptv-org.github.io/epg/guides/gw.xml
🇬🇾 Guyana 53 https://iptv-org.github.io/epg/guides/gy.xml
🇭🇹 Haiti 91 https://iptv-org.github.io/epg/guides/ht.xml
🇭🇲 Heard Island and McDonald Islands 51 https://iptv-org.github.io/epg/guides/hm.xml
🇭🇳 Honduras 204 https://iptv-org.github.io/epg/guides/hn.xml
🇭🇰 Hong Kong 152 https://iptv-org.github.io/epg/guides/hk.xml
🇭🇺 Hungary 203 https://iptv-org.github.io/epg/guides/hu.xml
🇮🇸 Iceland 102 https://iptv-org.github.io/epg/guides/is.xml
🇮🇳 India 417 https://iptv-org.github.io/epg/guides/in.xml
🇮🇩 Indonesia 198 https://iptv-org.github.io/epg/guides/id.xml
🇮🇷 Iran 88 https://iptv-org.github.io/epg/guides/ir.xml
🇮🇶 Iraq 102 https://iptv-org.github.io/epg/guides/iq.xml
🇮🇪 Ireland 150 https://iptv-org.github.io/epg/guides/ie.xml
🇮🇲 Isle of Man 51 https://iptv-org.github.io/epg/guides/im.xml
🇮🇱 Israel 78 https://iptv-org.github.io/epg/guides/il.xml
🇮🇹 Italy 249 https://iptv-org.github.io/epg/guides/it.xml
🇨🇮 Ivory Coast 119 https://iptv-org.github.io/epg/guides/ci.xml
🇯🇲 Jamaica 65 https://iptv-org.github.io/epg/guides/jm.xml
🇯🇵 Japan 186 https://iptv-org.github.io/epg/guides/jp.xml
🇯🇪 Jersey 52 https://iptv-org.github.io/epg/guides/je.xml
🇯🇴 Jordan 101 https://iptv-org.github.io/epg/guides/jo.xml
🇰🇿 Kazakhstan 96 https://iptv-org.github.io/epg/guides/kz.xml
🇰🇪 Kenya 112 https://iptv-org.github.io/epg/guides/ke.xml
🇰🇮 Kiribati 62 https://iptv-org.github.io/epg/guides/ki.xml
🇽🇰 Kosovo 78 https://iptv-org.github.io/epg/guides/xk.xml
🇰🇼 Kuwait 111 https://iptv-org.github.io/epg/guides/kw.xml
🇰🇬 Kyrgyzstan 64 https://iptv-org.github.io/epg/guides/kg.xml
🇱🇦 Laos 97 https://iptv-org.github.io/epg/guides/la.xml
🇱🇻 Latvia 96 https://iptv-org.github.io/epg/guides/lv.xml
🇱🇧 Lebanon 104 https://iptv-org.github.io/epg/guides/lb.xml
🇱🇸 Lesotho 101 https://iptv-org.github.io/epg/guides/ls.xml
🇱🇷 Liberia 100 https://iptv-org.github.io/epg/guides/lr.xml
🇱🇾 Libya 123 https://iptv-org.github.io/epg/guides/ly.xml
🇱🇮 Liechtenstein 91 https://iptv-org.github.io/epg/guides/li.xml
🇱🇹 Lithuania 111 https://iptv-org.github.io/epg/guides/lt.xml
🇱🇺 Luxembourg 103 https://iptv-org.github.io/epg/guides/lu.xml
🇲🇴 Macao 57 https://iptv-org.github.io/epg/guides/mo.xml
🇲🇬 Madagascar 116 https://iptv-org.github.io/epg/guides/mg.xml
🇲🇼 Malawi 103 https://iptv-org.github.io/epg/guides/mw.xml
🇲🇾 Malaysia 164 https://iptv-org.github.io/epg/guides/my.xml
🇲🇻 Maldives 69 https://iptv-org.github.io/epg/guides/mv.xml
🇲🇱 Mali 116 https://iptv-org.github.io/epg/guides/ml.xml
🇲🇹 Malta 109 https://iptv-org.github.io/epg/guides/mt.xml
🇲🇭 Marshall Islands 62 https://iptv-org.github.io/epg/guides/mh.xml
🇲🇶 Martinique 83 https://iptv-org.github.io/epg/guides/mq.xml
🇲🇷 Mauritania 120 https://iptv-org.github.io/epg/guides/mr.xml
🇲🇺 Mauritius 109 https://iptv-org.github.io/epg/guides/mu.xml
🇾🇹 Mayotte 100 https://iptv-org.github.io/epg/guides/yt.xml
🇲🇽 Mexico 254 https://iptv-org.github.io/epg/guides/mx.xml
🇫🇲 Micronesia 62 https://iptv-org.github.io/epg/guides/fm.xml
🇲🇩 Moldova 97 https://iptv-org.github.io/epg/guides/md.xml
🇲🇨 Monaco 87 https://iptv-org.github.io/epg/guides/mc.xml
🇲🇳 Mongolia 60 https://iptv-org.github.io/epg/guides/mn.xml
🇲🇪 Montenegro 99 https://iptv-org.github.io/epg/guides/me.xml
🇲🇸 Montserrat 63 https://iptv-org.github.io/epg/guides/ms.xml
🇲🇦 Morocco 124 https://iptv-org.github.io/epg/guides/ma.xml
🇲🇿 Mozambique 118 https://iptv-org.github.io/epg/guides/mz.xml
🇲🇲 Myanmar (Burma) 97 https://iptv-org.github.io/epg/guides/mm.xml
🇳🇦 Namibia 102 https://iptv-org.github.io/epg/guides/na.xml
🇳🇷 Nauru 62 https://iptv-org.github.io/epg/guides/nr.xml
🇳🇵 Nepal 72 https://iptv-org.github.io/epg/guides/np.xml
🇳🇱 Netherlands 256 https://iptv-org.github.io/epg/guides/nl.xml
🇳🇨 New Caledonia 63 https://iptv-org.github.io/epg/guides/nc.xml
🇳🇿 New Zealand 145 https://iptv-org.github.io/epg/guides/nz.xml
🇳🇮 Nicaragua 194 https://iptv-org.github.io/epg/guides/ni.xml
🇳🇪 Niger 110 https://iptv-org.github.io/epg/guides/ne.xml
🇳🇬 Nigeria 134 https://iptv-org.github.io/epg/guides/ng.xml
🇳🇺 Niue 62 https://iptv-org.github.io/epg/guides/nu.xml
🇳🇫 Norfolk Island 62 https://iptv-org.github.io/epg/guides/nf.xml
🇰🇵 North Korea 60 https://iptv-org.github.io/epg/guides/kp.xml
🇲🇰 North Macedonia 104 https://iptv-org.github.io/epg/guides/mk.xml
🇲🇵 Northern Mariana Islands 62 https://iptv-org.github.io/epg/guides/mp.xml
🇳🇴 Norway 114 https://iptv-org.github.io/epg/guides/no.xml
🇴🇲 Oman 98 https://iptv-org.github.io/epg/guides/om.xml
🇵🇰 Pakistan 72 https://iptv-org.github.io/epg/guides/pk.xml
🇵🇼 Palau 62 https://iptv-org.github.io/epg/guides/pw.xml
🇵🇸 Palestine 99 https://iptv-org.github.io/epg/guides/ps.xml
🇵🇦 Panama 197 https://iptv-org.github.io/epg/guides/pa.xml
🇵🇬 Papua New Guinea 62 https://iptv-org.github.io/epg/guides/pg.xml
🇵🇾 Paraguay 213 https://iptv-org.github.io/epg/guides/py.xml
🇵🇪 Peru 228 https://iptv-org.github.io/epg/guides/pe.xml
🇵🇭 Philippines 154 https://iptv-org.github.io/epg/guides/ph.xml
🇵🇳 Pitcairn Islands 62 https://iptv-org.github.io/epg/guides/pn.xml
🇵🇱 Poland 263 https://iptv-org.github.io/epg/guides/pl.xml
🇵🇹 Portugal 174 https://iptv-org.github.io/epg/guides/pt.xml
🇵🇷 Puerto Rico 191 https://iptv-org.github.io/epg/guides/pr.xml
🇶🇦 Qatar 143 https://iptv-org.github.io/epg/guides/qa.xml
🇨🇬 Republic of the Congo 114 https://iptv-org.github.io/epg/guides/cg.xml
🇷🇴 Romania 199 https://iptv-org.github.io/epg/guides/ro.xml
🇷🇺 Russia 272 https://iptv-org.github.io/epg/guides/ru.xml
🇷🇼 Rwanda 118 https://iptv-org.github.io/epg/guides/rw.xml
🇷🇪 Réunion 101 https://iptv-org.github.io/epg/guides/re.xml
🇧🇱 Saint Barthélemy 77 https://iptv-org.github.io/epg/guides/bl.xml
🇸🇭 Saint Helena 94 https://iptv-org.github.io/epg/guides/sh.xml
🇰🇳 Saint Kitts and Nevis 63 https://iptv-org.github.io/epg/guides/kn.xml
🇱🇨 Saint Lucia 63 https://iptv-org.github.io/epg/guides/lc.xml
🇲🇫 Saint Martin 77 https://iptv-org.github.io/epg/guides/mf.xml
🇵🇲 Saint Pierre and Miquelon 60 https://iptv-org.github.io/epg/guides/pm.xml
🇻🇨 Saint Vincent and the Grenadines 63 https://iptv-org.github.io/epg/guides/vc.xml
🇼🇸 Samoa 62 https://iptv-org.github.io/epg/guides/ws.xml
🇸🇲 San Marino 84 https://iptv-org.github.io/epg/guides/sm.xml
🇸🇦 Saudi Arabia 117 https://iptv-org.github.io/epg/guides/sa.xml
🇸🇳 Senegal 120 https://iptv-org.github.io/epg/guides/sn.xml
🇷🇸 Serbia 305 https://iptv-org.github.io/epg/guides/rs.xml
🇸🇨 Seychelles 107 https://iptv-org.github.io/epg/guides/sc.xml
🇸🇱 Sierra Leone 101 https://iptv-org.github.io/epg/guides/sl.xml
🇸🇬 Singapore 145 https://iptv-org.github.io/epg/guides/sg.xml
🇸🇽 Sint Maarten 71 https://iptv-org.github.io/epg/guides/sx.xml
🇸🇰 Slovakia 170 https://iptv-org.github.io/epg/guides/sk.xml
🇸🇮 Slovenia 153 https://iptv-org.github.io/epg/guides/si.xml
🇸🇧 Solomon Islands 62 https://iptv-org.github.io/epg/guides/sb.xml
🇸🇴 Somalia 121 https://iptv-org.github.io/epg/guides/so.xml
🇿🇦 South Africa 202 https://iptv-org.github.io/epg/guides/za.xml
🇬🇸 South Georgia and the South Sandwich Islands 53 https://iptv-org.github.io/epg/guides/gs.xml
🇰🇷 South Korea 189 https://iptv-org.github.io/epg/guides/kr.xml
🇸🇸 South Sudan 101 https://iptv-org.github.io/epg/guides/ss.xml
🇪🇸 Spain 245 https://iptv-org.github.io/epg/guides/es.xml
🇱🇰 Sri Lanka 69 https://iptv-org.github.io/epg/guides/lk.xml
🇸🇩 Sudan 128 https://iptv-org.github.io/epg/guides/sd.xml
🇸🇷 Suriname 57 https://iptv-org.github.io/epg/guides/sr.xml
🇸🇯 Svalbard and Jan Mayen 51 https://iptv-org.github.io/epg/guides/sj.xml
🇸🇿 Swaziland 100 https://iptv-org.github.io/epg/guides/sz.xml
🇸🇪 Sweden 176 https://iptv-org.github.io/epg/guides/se.xml
🇨🇭 Switzerland 225 https://iptv-org.github.io/epg/guides/ch.xml
🇸🇾 Syria 100 https://iptv-org.github.io/epg/guides/sy.xml
🇸🇹 São Tomé and Príncipe 107 https://iptv-org.github.io/epg/guides/st.xml
🇹🇼 Taiwan 67 https://iptv-org.github.io/epg/guides/tw.xml
🇹🇯 Tajikistan 63 https://iptv-org.github.io/epg/guides/tj.xml
🇹🇿 Tanzania 109 https://iptv-org.github.io/epg/guides/tz.xml
🇹🇭 Thailand 151 https://iptv-org.github.io/epg/guides/th.xml
🇹🇬 Togo 111 https://iptv-org.github.io/epg/guides/tg.xml
🇹🇰 Tokelau 62 https://iptv-org.github.io/epg/guides/tk.xml
🇹🇴 Tonga 62 https://iptv-org.github.io/epg/guides/to.xml
🇹🇹 Trinidad and Tobago 63 https://iptv-org.github.io/epg/guides/tt.xml
🇹🇳 Tunisia 125 https://iptv-org.github.io/epg/guides/tn.xml
🇹🇷 Turkey 253 https://iptv-org.github.io/epg/guides/tr.xml
🇹🇲 Turkmenistan 59 https://iptv-org.github.io/epg/guides/tm.xml
🇹🇨 Turks and Caicos Islands 63 https://iptv-org.github.io/epg/guides/tc.xml
🇹🇻 Tuvalu 62 https://iptv-org.github.io/epg/guides/tv.xml
🇺🇲 U.S. Minor Outlying Islands 51 https://iptv-org.github.io/epg/guides/um.xml
🇻🇮 U.S. Virgin Islands 63 https://iptv-org.github.io/epg/guides/vi.xml
🇺🇬 Uganda 110 https://iptv-org.github.io/epg/guides/ug.xml
🇺🇦 Ukraine 83 https://iptv-org.github.io/epg/guides/ua.xml
🇦🇪 United Arab Emirates 133 https://iptv-org.github.io/epg/guides/ae.xml
🇬🇧 United Kingdom 411 https://iptv-org.github.io/epg/guides/uk.xml
🇺🇸 United States 1380 https://iptv-org.github.io/epg/guides/us.xml
🇺🇾 Uruguay 220 https://iptv-org.github.io/epg/guides/uy.xml
🇺🇿 Uzbekistan 63 https://iptv-org.github.io/epg/guides/uz.xml
🇻🇺 Vanuatu 63 https://iptv-org.github.io/epg/guides/vu.xml
🇻🇦 Vatican City 84 https://iptv-org.github.io/epg/guides/va.xml
🇻🇪 Venezuela 209 https://iptv-org.github.io/epg/guides/ve.xml
🇻🇳 Vietnam 99 https://iptv-org.github.io/epg/guides/vn.xml
🇼🇫 Wallis and Futuna 63 https://iptv-org.github.io/epg/guides/wf.xml
🇪🇭 Western Sahara 108 https://iptv-org.github.io/epg/guides/eh.xml
🇾🇪 Yemen 98 https://iptv-org.github.io/epg/guides/ye.xml
🇿🇲 Zambia 109 https://iptv-org.github.io/epg/guides/zm.xml
🇿🇼 Zimbabwe 102 https://iptv-org.github.io/epg/guides/zw.xml
🇦🇽 Åland 58 https://iptv-org.github.io/epg/guides/ax.xml
  • The first thing the script does is set the default timezone to UTC using the date_default_timezone_set() function. This ensures that the current date and time is retrieved in the UTC timezone.
  • The script then retrieves the current date and time in the format “YYYYMMDDHHmm” using the date() function, and stores it in the variable $now. This value will be used later to check if a program is currently airing or starts later today.
  • Next, the script checks if the GET request has been made using the isset() function and the $_GET array. If the GET request has been made, the script extracts the channelId parameter from the $_GET array and stores it in the variable $channelId.
  • The script then creates a new XMLReader object and opens the XML file at the specified URL using the open() method.
  • The script enters a loop that reads the XML file incrementally using the read() method of the XMLReader object. At each iteration, the script checks the type and name of the current node using the nodeType and name properties of the XMLReader object.
  • If the current node is a “channel” element, the script loads the element into a SimpleXMLElement object using the readOuterXML() method of the XMLReader object, and extracts the id attribute of the element. If the id attribute matches the channelId parameter passed in the GET request, the script extracts the display-name, icon, and url elements of the channel element, and stores them in the variables $displayName, $iconUrl, and $url, respectively. It then checks if these variables are set, and if they are, it prints the channel information to the webpage.
  • If the current node is a “programme” element, the script loads the element into a SimpleXMLElement object using the readOuterXML() method of the XMLReader object, and extracts the start and stop attributes of the element. It then converts these attributes to the desired format using the strtotime() and date() functions, and stores the result in the variables $formattedStartTime and $formattedStopTime. The script also extracts the channel attribute of the programme element, and stores it in the variable $programChannelId.
  • If the $programChannelId variable matches the channelId parameter passed in the GET request, the script checks if the program is currently airing or starts later today by comparing the $startTime and $stopTime variables to the $now variable. If the program is currently airing or starts later today, the script extracts the title, desc, category, and icon elements of the programme element, and stores them in the variables $title, $description, $category, and iconUrl, respectively. It then prints the program information to the webpage.
  • After the loop has finished executing, the script closes the XML file using the close() method of the XMLReader object.

To use this script, you would need to send a GET request to the script with the desired channel ID passed as a parameter. For example, if you wanted to get information about the channel with the ID “12345”, you would send a GET request to “localhost/epg.php?channelId=NameOfTheChannelID”.

The channelID shoud be the same as in the XML.

When the script receives the GET request, it will retrieve the XML file, parse it incrementally using an XMLReader object, and extract the information about the desired channel and its current program. It will then print this information to the webpage.

If the GET request is not made or if the specified channel ID is not found in the XML file, the script will not output any information.

EX:

epgscript

Full script:


<?php

// Set the timezone to the desired timezone
date_default_timezone_set('UTC');

// Get the current date and time in the desired format
$now = date('YmdHi');

// Check if the GET request has been made
if (isset($_GET['channelId'])) {
// Get the channel ID from the GET request
$channelId = $_GET['channelId'];

// Create a new XMLReader object
$reader = new XMLReader();

// Open the XML file
$reader->open('https://iptv-org.github.io/epg/guides/pl.xml');

// Read the file incrementally
while ($reader->read()) {
// If the current node is a "channel" element
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'channel') {
// Load the "channel" element into a SimpleXMLElement object
$channel = new SimpleXMLElement($reader->readOuterXML());

// Extract the channel ID
$currentChannelId = (string)$channel['id'];

// If the channel ID matches the one from the GET request
if ($currentChannelId == $channelId) {
// Extract the information you need from the "channel" element
$displayName = (string)$channel->{'display-name'};
$iconUrl = (string)$channel->icon['src'];
$url = (string)$channel->url;

// Print the channel information
// Check if the variables are set
if (isset($channelId) && isset($displayName) && isset($iconUrl)) {
// Print the channel information
echo "<h1>Channel ID: $channelId</h1>";
echo "<p>Display name: $displayName</p>";
echo "<img src='$iconUrl'>";
}
}
}

// If the current node is a "programme" element
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'programme') {
// Load the "programme" element into a SimpleXMLElement object
$program = new SimpleXMLElement($reader->readOuterXML());

// Extract the start and stop time of the program
// Extract the start and stop time of the program
$startTime = (string)$program['start'];
$stopTime = (string)$program['stop'];

// Convert the start and stop time to the desired format
$formattedStartTime = date('H:i - d.m.Y', strtotime($startTime));
$formattedStopTime = date('H:i - d.m.Y', strtotime($stopTime));

// Extract the channel ID of the program
$programChannelId = (string)$program['channel'];

// If the channel ID of the program matches the one from the GET request
if ($programChannelId == $channelId) {
// Check if the program is currently airing or starts later today
if ($startTime <= $now && $now <= $stopTime || $startTime >= $now) {
// Extract the information you need from the "programme" element
$title = (string)$program->title;
$description = (string)$program->desc;
$category = (string)$program->category;
$iconUrl = (string)$program->icon['src'];

// Print the program information
echo "<h2>Title: $title</h2>";
echo "<img src='$iconUrl'>";
echo "<p>Description: $description</p>";
echo "<p>Category: $category</p>";
echo "<p>Start time: $formattedStartTime</p>";
echo "<p>Stop time: $formattedStopTime</p>";
}
}
}
}

// Close the XML file
$reader->close();
}
?>

Was this helpful?

1 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *