RUC ASDCs Overview and Analysis
The content delves into the RUC optimization process under RTC, focusing on ASDCs for ensuring reliability and meeting load forecast and AS plan. It discusses the differences between RUC and SCED optimizations, the analysis of required ASDCs, and historical data analysis for improving penalty curves.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Chapter 7 PHP Basics Dr. Ahmad Al-Sabhany CS Department AlMaarifUniversity College
Outline Introduction Hello World! & Basic Examples Cool Example Variables Functions Comparisons and logical expressions If & if Else Statements PHP loops include and require Stitching PHP and Bootstrap Example Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 2
Introduction What is PHP? PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on the server PHP is free to download and use PHP is an amazing and popular language! It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)! It is deep enough to run large social networks! It is also easy enough to be a beginner's first server side language! Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 3
What Can PHP Do? PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files on the server PHP can collect form data PHP can send and receive cookies PHP can add, delete, modify data in your database PHP can be used to control user-access PHP can encrypt data Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 4
PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends with ?> In PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are not case-sensitive. <?php // PHP code goes here ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 5
Before Running PHP Running PHP needs three main requirements PHP, the language itself Web Server such as Apache, Nginx Database such MySql, MariaDB <?php echo Hello World!"; ?> PHP Apache MySql PHP Environment Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 6
Hello World! Example In the webserver, create a PHP file (index.php) <?php $txt = "PHP"; echo "I love $txt!"; ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 7
Example: Case Sensitivity In this example only the first printing statement will display the text red COLOR, and coLOR are considered other variables <!DOCTYPE html> <html> <body> <?php $color="red"; echo"My car is ".$color."<br>"; echo"My house is ".$COLOR."<br>"; echo"My boat is ".$coLOR."<br>"; ?> </body> </html> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 8
PHP Variables PHP is a Loosely Typed Language, no need to tell PHP which data type the variable is. <?php $txt="PHP"; echo"I love $txt!"; ?> <?php $txt="PHP"; echo"I love ".$txt."!"; ?> <?php $txt="Hello world!"; $x=5; $y=10.5; echo$txt; echo"<br>"; echo$x; echo"<br>"; echo$y;?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 9
Variables Scope <?php $x=5; $y=10; functionmyTest(){ global$x,$y; $y=$x+$y; } myTest(); echo$y;// outputs 15 ?> Global: A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function. Local: A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function. Static: Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job. Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 10
Echo & Print <?php $txt1 = "Learn PHP"; $txt2 = "W3Schools.com"; $x = 5; $y = 4; <?php $txt1 = "Learn PHP"; $txt2 = "W3Schools.com"; $x = 5; $y = 4; print "<h2>" . $txt1 . "</h2>"; print "Study PHP at " . $txt2 . "<br>"; print $x + $y; ?> echo "<h2>" . $txt1 . "</h2>"; echo "Study PHP at " . $txt2 . "<br>"; echo $x + $y; ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 11
Data Types Variables can store data of different types, and different data types can do different things. PHP supports the following data types: String Integer Float (floating point numbers - also called double) Boolean Array Object NULL Resource Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 12
Data Types PHP String A string is a sequence of characters, like "Hello world!". <?php $x = "Hello world!"; $y = 'Hello world!'; A string can be any text inside quotes. You can use single or double quotes: echo $x; echo "<br>"; echo $y; ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 13
Data Types PHP Integer An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647. Rules for integers: An integer must have at least one digit An integer must not have a decimal point An integer can be either positive or negative <?php $x = 5985; var_dump($x); ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 14
Data Types PHP Float A float (floating point number) is a number with a decimal point or a number in exponential form. In the following example $x is a float. The PHP var_dump() function returns the data type and value: <?php $x = 58.12; var_dump($x); ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 15
Data Types PHP Boolean A Boolean represents two possible states: TRUE or FALSE. Booleans are often used in conditional testing. You will learn more about conditional testing in a later chapter of this tutorial. $x = true; $y = false; <?php $x = true; var_dump($x); ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 16
Data Types PHP Array An array stores multiple values in one single variable. In the following example $cars is an array. The PHP var_dump() function returns the data type and value: <?php $cars = array("Volvo","BMW","T oyota"); var_dump($cars); ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 17
Data Types PHP Object <!DOCTYPE html> <html> <body> <?php class Car { public $color; public $model; public function __construct($color, $model) { $this->color = $color; $this->model = $model; } public function message() { return "My car is a " . $this->color . " " . $this->model . "!"; } } $myCar = new Car("black", "Volvo"); echo $myCar -> message(); echo "<br>"; $myCar = new Car("red", "Toyota"); echo $myCar -> message(); ?> </body> </html> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 18
PHP Math Common predefined mathematical functions in PHP: max() Returns the highest value in an array, or the highest value of several specified values min() Returns the lowest value in an array, or the lowest value of several specified values abs() Returns the absolute (positive) value of a number floor() Rounds a number down to the nearest integer ceil() Rounds a number up to the nearest integer cos() Returns the cosine of a number sin() Returns the sine of a number tan() Returns the tan of a number pi() Returns the value of PI pow() Returns x raised to the power of y sqrt() Returns the square root of a number exp() Calculates the exponent of e log() Returns the natural logarithm of a number log10() Returns the base-10 logarithm of a number rand() Generates a random integer Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 19
PHP Math abs() Return the absolute value of different numbers: <?php echo(abs(6.7) . "<br>"); echo(abs(-6.7) . "<br>"); echo(abs(-3) . "<br>"); echo(abs(3)); ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 20
PHP Math ceil(), floor(), round() ceil example: <?php echo(ceil(0.60) . "<br>"); echo(ceil(0.40) . "<br>"); echo(ceil(5) . "<br>"); echo(ceil(5.1) . "<br>"); echo(ceil(-5.1) . "<br>"); echo(ceil(-5.9)); ?> floor example: round example: <?php echo(floor(0.60) . "<br>"); echo(floor(0.40) . "<br>"); echo(floor(5) . "<br>"); echo(floor(5.1) . "<br>"); echo(floor(-5.1) . "<br>"); echo(floor(-5.9)); ?> <?php echo(round(0.60) . "<br>"); echo(round(0.50) . "<br>"); echo(round(0.49) . "<br>"); echo(round(-4.40) . "<br>"); echo(round(-4.60)); ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 21
PHP Math pow() & sqrt() <?php echo(pow(2,4) . "<br>"); echo(pow(-2,4) . "<br>"); echo(pow(-2,-4) . "<br>"); echo(pow(-2,-3.2)); ?> <?php echo(sqrt(0) . "<br>"); echo(sqrt(1) . "<br>"); echo(sqrt(9) . "<br>"); echo(sqrt(0.64) . "<br>"); echo(sqrt(-9)); ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 22
PHP Constants A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constants are automatically global across the entire script. <?php define("GREETING", "Welcome to W3Schools.com!", true); echo greeting; ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 23
PHP Constant Arrays In PHP7, you can create an Array constant using the define() function. <?php define("cars", [ "Alfa Romeo", "BMW", "Toyota" ]); echo cars[0]; ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 24
PHP Operators PHP Operators Operators are used to perform operations on variables and values. PHP divides the operators in the following groups: Arithmetic operators Assignment operators Comparison operators Increment/Decrement operators Logical operators String operators Array operators Conditional assignment operators Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 25
PHP Arithmetic Operators Operator Name Example Result Show it + Try it Addition $x + $y Sum of $x and $y - Try it Subtraction $x - $y Difference of $x and $y * Try it Multiplication $x * $y Product of $x and $y / Try it Division $x / $y Quotient of $x and $y % Try it Modulus $x % $y Remainder of $x divided by $y ** Try it Exponentiation $x ** $y Result of raising $x to the $y'th power Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 26
PHP Comparison Operators Operato r Name Example Result Show it == Try it Equal $x == $y Returns true if $x is equal to $y === Try it Identical $x === $y Returns true if $x is equal to $y, and they are of the same type =! Try it Not equal $x != $y Returns true if $x is not equal to $y >< Try it Not equal $x <> $y Returns true if $x is not equal to $y ==! Try it Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type > Try it Greater than $x > $y Returns true if $x is greater than $y < Try it Less than $x < $y Returns true if $x is less than $y = > Try it Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y = < Try it Less than or equal to $x <= $y Returns true if $x is less than or equal to $y 1/9/2022 Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 27
PHP Logical Operators Operator Name Example Result Show it and And $x and $y True if both $x and $y are true Try it or Or $x or $y True if either $x or $y is true Try it xor Xor $x xor $y True if either $x or $y is true, but not both Try it And $x && $y True if both $x and $y are true && Try it Or $x || $y True if either $x or $y is true || Try it Not !$x True if $x is not true ! Try it 1/9/2022 Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 28
PHP Conditional Statements Very often when you write code, you want to perform different actions for different conditions. You can use conditional statements in your code to do this. In PHP we have the following conditional statements: if statement - executes some code if one condition is true if...else statement - executes some code if a condition is true and another code if that condition is false if...elseif...else statement - executes different codes for more than two conditions switch statement - selects one of many blocks of code to be executed Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 29
if statement The if statement executes some code if one condition is true. if (condition) { code to be executed if condition is true; } <?php $mark = 50; if ($mark >= 50) { echo "congrats! you passed"; } ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 30
if...else The if...else statement executes some code if a condition is true and another code if that condition is false. if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; } <?php $t = date("H"); if ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 31
The switch Statement Use the switch statement to select one of many blocks of code to be executed. switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break; ... default: code to be executed if n is different from all labels; } Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 32
The switch Statement Example <?php $favcolor = "black"; switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": echo "Your favorite color is blue!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "Your favorite color is neither red, blue, nor green!"; }?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 33
PHP Loops Loops are used to execute the same block of code again and again, as long as a certain condition is true. In PHP, we have the following loop types: while - loops through a block of code as long as the specified condition is true do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true for - loops through a block of code a specified number of times foreach - loops through a block of code for each element in an array Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 34
while loop The while loop - Loops through a block of code as long as the specified condition is true. Syntax: while (condition is true) { code to be executed; } Example: <?php $x = 1; while($x <= 5) { echo "The number is: $x <br>"; $x++; } ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 35
foreach Loop The foreach loop - Loops through a block of code for each element in an array. The foreach loop works only on arrays, and is used to loop through each key/value pair in an array. Syntax: foreach ($array as $value) { code to be executed; } For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element. Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 36
foreach Examples <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?> <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); foreach($age as $x => $val) { echo "$x = $val<br>"; } ?> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 37
Include & Require The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website. The include and require statements are identical, except upon failure: require will produce a fatal error (E_COMPILE_ERROR) and stop the script include will only produce a warning (E_WARNING) and the script will continue include 'filename'; or require 'filename'; Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 38
Function <?php function isPrime($num) { if ($num < 2) { return false; } for ($i = 2; $i <= sqrt($num); $i++) { if ($num % $i == 0) { return false; } } return true; } Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 39
Cool Example 1 <html lang="en"> <head> <title>Random Password</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin: 100px; } p {color: blue; font-size: 18px; } .message {font-size: 16px; margin-top: 10px; } </style> </head> <body> <?php function generateRandomPassword($length = 15) { $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?'; $password = ''; for ($i = 0; $i < $length; $i++) { $password .= $characters[rand(0, strlen($characters) - 1)]; } return $password; } $randomPassword = generateRandomPassword(); echo "Random Password: " . $randomPassword; ?> </div></body></html> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 40
Cool Example 2 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Prime Number Checker</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin: 50px; } form {margin-top: 20px;} h2 {color: #4CAF50; } .error {color: #FF0000; } </style> </head> <body> <?php function isPrime($num) { if ($num < 2) { return false; } for ($i = 2; $i <= sqrt($num); $i++) { if ($num % $i == 0) { return false; } } return true;} $userNumber = $resultMessage = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $userNumber = isset($_POST["number"]) ? (int)$_POST["number"] : 0; if (isPrime($userNumber)) { $resultMessage = "Yes, $userNumber is a prime number!"; } else { $nextPrime = $userNumber + 1; while (!isPrime($nextPrime)) { $nextPrime++; } $resultMessage = "No, $userNumber is not a prime number. The next prime number is $nextPrime."; }} ?> <h2><?php echo $resultMessage; ?></h2> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> <label for="number">Enter a number:</label> <input type="number" id="number" name="number" value="<?php echo $userNumber; ?>" required> <button type="submit">Check Prime</button> </form> </body> </html> Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 41
Training Stitch PHP with Bootstrap Example Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 42
Show Case Try it Yourself ! alsabhany@uoa.edu.iq Dr. Ahmad AlSabhany CS Dept | AlMaarif University College 1/9/2022 43