Thursday, 5 May 2022

Advance PHP-Slip4b-Create an xml file which should comprise the following: Sachin Tendulkar 2000 100 20 For at least 5 players. Write a PHP script to display the details of players who have scored more than 1200 runs and at least 50 wickets.

 Create an xml file which should comprise the following:

<cricket>

 <player>Sachin Tendulkar</player>

 <runs>2000</runs>

 <wickets> 100</wickets>

<noofnotout>20</noofnotout>

 </cricket>

For at least 5 players. Write a PHP script to display the details of players who have scored more than 1200 runs and at least 50 wickets.

 

Cricket.xml

 

<?xml version="1.0"?>

<?xml-stylesheet type="text/css"?>

  

<cricketinfo>

 

<cricket>

<player>Sachin Tendulkar</player>

<runs>2000</runs>

 wickets> 100</wickets>

<noofnotout>20</noofnotout>

</cricket>

  <cricket>

<player>Rohit Sharma</player>

<runs>1000</runs>

<wickets>40</wickets>

<noofnotout>10</noofnotout>

</cricket>

 <cricket>

<player>Dhoni</player>

<runs>1000</runs>

<wickets>40</wickets>

<noofnotout>10</noofnotout>

 </cricket>

 <cricket>

<player>Virat Kohali</player>

<runs>1000</runs>

<wickets>40</wickets>

<noofnotout>10</noofnotout>

</cricket>

  <cricket>

<player>Jadeja</player>

<runs>1000</runs>

<wickets>40</wickets>

<noofnotout>10</noofnotout>

 </cricket> 

 </cricketinfo>

 

  

Cricket.php

 

<?php

 // Load xml file into xml_data variable

//$xml_data = simplexml_load_file("http://localhost/arprogram/cricket.xml") or

//die("Error: Object Creation failure");

  

$xml_data = simplexml_load_file("http://localhost:8080/SEM4/cricket.xml") or

die("Error: Object Creation failure");

 // Use foreach loop to display data and for sub elements access,We will use children() function

foreach ($xml_data->children() as $data)

{

 //display each sub element in xml file

$run=$data->runs;

$wic=$data->wickets;

$name=$data->player;

if($run >=1200 && $wic >= 50)

{

echo "<br>------------------------------------";

echo "<br>".$name;

}

}

 ?>