---
- PHP (Hypertext Preprocessor), web geliştirme için tasarlanmış bir sunucu taraflı betik dilidir.
- HTML içine gömülebilir.
- Dinamik web siteleri, CMS (WordPress), framework (Laravel) geliştirmede yaygın olarak kullanılır.
<?php
echo "Merhaba PHP 🚀";
?>
📌 Açıklama:
<?php ... ?>
→ PHP kod bloğunu başlatır ve bitirir.echo
→ ekrana yazı yazar.
<?php
$sayi = 10; // Integer
$pi = 3.14; // Float
$isim = "Ebrar"; // String
$dogruMu = true; // Boolean
?>
📌 PHP’de tüm değişkenler $
ile başlar.
<?php
$a = 5;
$b = 2;
echo $a + $b; // Toplama
echo $a - $b; // Çıkarma
echo $a * $b; // Çarpma
echo $a / $b; // Bölme
echo $a % $b; // Mod
?>
<?php
$yas = 18;
if ($yas >= 18) {
echo "Reşitsiniz ✅";
} else {
echo "Reşit değilsiniz ❌";
}
?>
<?php
$gun = 3;
switch ($gun) {
case 1: echo "Pazartesi"; break;
case 2: echo "Salı"; break;
case 3: echo "Çarşamba"; break;
default: echo "Bilinmiyor"; break;
}
?>
<?php
for ($i = 1; $i <= 5; $i++) {
echo $i;
}
?>
<?php
$sayac = 0;
while ($sayac < 3) {
echo "Sayaç: $sayac";
$sayac++;
}
?>
<?php
function kare($x) {
return $x * $x;
}
echo kare(5);
?>
<?php
$meyveler = array("Elma", "Armut", "Muz");
foreach ($meyveler as $meyve) {
echo $meyve;
}
?>
👉 Modern kullanım:
$meyveler = ["Elma", "Armut", "Muz"];
📌 PHP genellikle form verisi işlemek için kullanılır.
<form method="post" action="ornek.php">
İsim: <input type="text" name="isim">
<input type="submit">
</form>
<?php
$isim = $_POST["isim"];
echo "Merhaba, $isim!";
?>
✔️ Değişkenler $
ile başlar.
✔️ PHP dosyaları .php
uzantılı olmalı.
✔️ Form verisi için $_GET
ve $_POST
kullanılır.
❌ Güvenlik için SQL Injection ve XSS açıklarına dikkat et!
- Kullanıcıdan isim al → “Merhaba, [isim]” yazdır.
- 1’den 100’e kadar sayıların toplamını ekrana yazdır.
- Bir dizi oluştur (
["elma","armut","muz"]
) → tümünü ekrana yazdır. - Basit bir hesap makinesi (toplama, çıkarma) yap.
PHP, web’in en çok kullanılan dillerinden biridir.
WordPress, Facebook’un ilk sürümü ve birçok dev proje PHP ile yazılmıştır.
Kısacası: Dinamik web = PHP 💛
- PHP (Hypertext Preprocessor) is a server-side scripting language designed for web development.
- It can be embedded in HTML.
- It is widely used in developing dynamic websites, CMS (WordPress), and frameworks (Laravel).
<?php
echo "Hello PHP 🚀";
?>
📌 Description:
<?php ... ?>
→ Starts and ends a block of PHP code.echo
→ prints text to the screen.
<?php
$number = 10; // Integer
$pi = 3.14; // Float
$name = "Ebrar"; // String
$true = true; // Boolean
?>
📌 All variables in PHP start with $
.
<?php
$a = 5;
$b = 2;
echo $a + $b; // Addition
echo $a - $b; // Subtraction
echo $a * $b; // Multiplication
echo $a / $b; // Division
echo $a % $b; // Mode
?>
<?php
$age = 18;
if ($age >= 18) {
echo "You are a minor ✅";
} else {
echo "You are a minor ❌";
}
?>
<?php
$day = 3;
switch ($day) {
case 1: echo "Monday"; break;
case 2: echo "Tuesday"; break;
case 3: echo "Wednesday"; break;
default: echo "Unknown"; break;
}
?>
<?php
for ($i = 1; $i <= 5; $i++) {
echo $i;
}
?>
<?php
$count = 0;
while ($counter < 3) {
echo "Counter: $counter";
$counter++;
}
?>
<?php
function square($x) {
return $x * $x;
}
echo square(5);
?>
<?php
$fruits = array("Apple", "Pear", "Banana");
foreach ($fruits as $fruit) {
echo $fruit;
}
?>
👉 Modern usage:
$fruits = ["Apple", "Pear", "Banana"];
📌 PHP is generally used to process form data.
<form method="post" action="example.php">
Name: <input type="text" name="name">
<input type="submit">
</form>
<?php
$name = $_POST["name"];
echo "Hello, $name!";
?>
✔️ Variables start with $
.
✔️ PHP files must have the .php
extension.
✔️ $_GET
and $_POST
are used for form data.
❌ Beware of SQL Injection and XSS vulnerabilities for security!
- Get the user's name → print "Hello, [name]".
- Print the sum of the numbers from 1 to 100.
- Create an array (
["apple","pear","banana"]
) → print all. - Create a simple calculator (addition, subtraction).
PHP is one of the most widely used languages on the web. WordPress, the first version of Facebook, and many other major projects are written in PHP. In short: Dynamic web = PHP 💛