9. VTU WEB TECHNOLOGY LAB | READ NOW

 VTU WEB TECHNOLOGY LAB

9] WRITE A PHP PROGRAM NAMED STATES.PY THAT DECLARES A VARIABLE STATES WITH VALUE “MISSISSIPPI ALABAMA TEXAS MASSACHUSETTS KANSAS”. WRITE A PHP PROGRAM THAT DOES THE FOLLOWING:

  1. SEARCH FOR A WORD IN VARIABLE STATES THAT ENDS IN XAS. STORE THIS WORD IN ELEMENT 0 OF A LIST NAMED STATESLIST
  2. SEARCH FOR A WORD IN STATES THAT BEGINS WITH K AND ENDS IN S. PERFORM A CASEINSENSITIVE COMPARISON. [NOTE: PASSING RE.IAS A SECOND PARAMETER TO METHOD COMPILE PERFORMS A CASE-INSENSITIVE COMPARISON.] STORE THIS WORD IN ELEMENT1 OF STATESLIST.
  3. SEARCH FOR A WORD IN STATES THAT BEGINS WITH M AND ENDS IN S. STORE THIS WORD IN ELEMENT 2 OF THE LIST.
  4. SEARCH FOR A WORD IN STATES THAT ENDS IN A. STORE THIS WORD IN ELEMENT 3 OF THE LIST.

STEPS TO EXECUTE PHP PROGRAM

  1. Copy the php code given below
  2. Save it with .php file name extension
  3. Place the file in the htdocs of XAAMP
  4. Start the XAAMP control panel
  5. Start Apache server
  6. Click on admin in XAMPP Control pale
  7. Replace the url dashboard name with your php file name
  8. Execution completed

Solution prog9.php

<html>
<body>
	<?php 
		$states = "Mississippi Alabama Texas Massachusetts Kansas";
		$b = explode(' ',$states);
		echo "<br>ORIGINAL ARRAY :<br>"; 
		foreach ( $b as $i => $value )
			echo "states[$i] = $value<br>";
		foreach ($b as $c) 
		{
			$n = strlen($c);
			if($c[$n-1]=='s' && $c[$n-2]=='a' && $c[$n-3]=='x')	$d[0] = $c;
			if($c[0]=='K' && $c[$n-1]=='s')	$d[1] = $c;
			if($c[0]=='M' && $c[$n-1]=='s')	$d[2] = $c;
			if($c[$n-1]=='a') $d[3] = $c;
		}
		echo "<br>RESULTANT ARRAY :<br>"; 
		for ($i=0; $i < count($d); $i++)
			echo "statesList[$i] = $d[$i]<br>";
	?>
</body>
</html>

WEB TECHNOLOGY – Output

WEB TECHNOLOGY

Leave a Reply

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

WhatsApp Icon Join For Job Alerts