0% found this document useful (0 votes)
16 views

This Ar Some Simple PHP Things

The document discusses PHP variables, data types, strings, arrays and functions. It explains how to define and use variables, integers, floats, strings and arrays in PHP. It also demonstrates various string and array functions.

Uploaded by

SAndrew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

This Ar Some Simple PHP Things

The document discusses PHP variables, data types, strings, arrays and functions. It explains how to define and use variables, integers, floats, strings and arrays in PHP. It also demonstrates various string and array functions.

Uploaded by

SAndrew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

<?php content ?

>

COMMENETS
// - (Pentru a folosi comentari, dar nu putem folosi mai multe raduri fara // in fata lor )

VARIABILE
Name Rules:
-

Start with $ sign


Followed by letter or underscore
Can contain letters, numbers, underscores or dashes
Cant contain spaces
Case-sensitive(differ A to a)

EX:
$item

ok

$var1 = 10;

$Item

ok

echo $var1;

$myVariabile

ok

$this_variable ok
$book3

$var2 = new to us; (String)


ok

echo $var2;
echo {$var2}Again
textul dorit

- Pentru a diferentia exact variabila de

STRING FUNCTIONS
<?php

$first = "The quick brown fox";


$second = " jumped over yje lazy dog.";

$third=$first;
$third .= $second;

echo $third;
?>

strtolower

toate cuv cu litere mici

<?php echo strtolower ($third); ?>

strtoupper

- toate cuv cu litere mari

<?php echo strtoupper ($third); ?>

ucfirst

- prima litera mare la primul cuv

ucwords
strlen
trim

- prima litera mare la fiecare cuv <?php echo ucwords ($third)?>

nr de caractere in $var

<?php echo strlen($third)?>

scote spatial din textul dintre

strstr

<?php echo ucfirst ($third)?>

<?php echo "A" . trim(" B C D ") . "E";?>

gaseste cuvantul dorit

<?php echo strstr ($third, "brown"); ?>

str_replaceinlocueste cuv quickcusuper

<?php echo str_replace("quick","super",

$third);?>

str_repeat

repeta $thierd 2 ori

<?php echo str_repeat ($third,2);?>

substr

ne da caractertele de la 5 la 10

strops

ne va spune pozitia cuv brown

strchr

ne va da un numar cu loc literei Z <?php echo strchr ($third, "z"); ?>

<?php echo substr ($third,5,10) ?>


<?php echo strpos ($third,"brown"); ?>

ex: echo strtolower ($var2);


INTEGERS and FLOATING POINTS(FLOATS)
INTEGERS
Basic math:
<?php
$var1=3;
$var2=4;
?>
Basic math: <?php echo ((1+2+$var1)*$var2)/2-5;?><br/>

abs

valoare absoluta

pow 2 la puterea 8
sqrt radacina patrata

<?php echo abs (0-300);?>


<?php echo pow (2,8); ?>
<?php echo sqrt (100);?>

fmod restul impartiri 20 la 7

<?php echo fmod (20,7);?>

rand un nr oarecare

<?php echo rand ()?>

rand nr oarecare din 1-10

<?php echo rand (1,10);?>

+= : <?php $var2 +=4; echo $var2; ?><br/>


-= : <?php $var2 -=4; echo $var2; ?><br/>
*= : <?php $var2 *=3; echo $var2; ?><br/>
/= : <?php $var2 /=4; echo $var2; ?><br/>
Folosind astfel se ia valoare var de la prima comnda si se trece prin fiecare
Com1: 4+4=8 => Com2: 8-4=4 => Com3: 4*3=12 => Com4: 12/4=3

Increment <?php $var2++; echo $var2; ?><br/> - aduna 1(++)


Decrement <?php $var2--; echo $var2; ?><br/> - scade 1(--)
1 si 1(1 intre ghilimele(string 1) nu e aceasi chestie)

FLOATS
Floats are decimal numbers(zecimale) ex: 3.12 ; 4.53
<?php echo $float = 3.14 ;?><br/>
<?php echo $float + 7 ;?><br/>
<?php echo 4/3 ; ?><br/>
Nu avem voie sa impartim la 0, ne va da eroare
Functii speciale floats:
Round: <?php echo round ($float, 1);?><br/> - va rotunji numarul la doar o decimala
Ceiling: <?php echo ceil ($float);?><br/>
Floor: <?php echo floor ($float);?><br/>

- va rotunj in sus
- va rotunji in jos

<?php echo "Is {$integer} integer? " . is_int($integer);?><br/>


float, numeric
<?php echo "Is {$float} integer?" . is_int($float);?><br/>
<br/>
<?php echo "Is {$integer} float? " . is_float($integer);?><br/>
<?php echo "Is {$float} float?" . is_float($float);?><br/>
<br/>
<?php echo "Is {$integer} numeric? " . is_numeric($integer);?><br/>
<?php echo "Is {$float} numeric?" . is_numeric($float);?><br/>

ARRAYS

Verificari integer,

Grupeaza integer si strings definindule, pastrand ordinea obiectelor in grup astfel sa


putem reveni la acele obiecte in funcie de pozitia lor.

<?php
$number = array(4,8,15,16,23,42);

- REZULTATUL ACESTEI COMENZI VA FI

4DEOARECE

echo $number[1];

NUMARATOARE INCEPE MEREU DE LA 0

?>
<?php $mixed = array (6,"fox","dog", array ("x", "y", "z")); ?
><br/>
<?php echo $mixed[2];?><br/>
<?php echo $mixed[3];?><br/>
<?php echo $mixed ?><br/>
<br/>
<pre>
<?php echo print_r($mixed);?><br/>
</pre>
<?php echo print_r($mixed);?>
array din array

- echo prin_r face descifrabil rezultatul din

<?php echo $mixed[3][1] ;?><br/>

-pentru a obtine rezultatul 1 din pozitia 3

a primului array

<?php $mixed[2] = "cat";?><br/> - Inlocuieste a 2 pozitie cu Cat


<?php $mixed[4] = "mouse";?><br/>

- Chiar daca nu avem pozitia 4 comanda

o va adauga la array

<?php $mixed[] = "horse";?><br/>

- Lasand spatial gol il va desemna mereu

sa fie ultima valoare

ASSOCIATIVE ARRAY
<?php $assoc = array ("first_name" => "Andrei", "last_name" =>"Sescu");?> -first
name este asociat cu Andrei
<?php echo $assoc["first_name"]; ?><br/>
<?php echo $assoc["first_name"] . " " . $assoc["last_name"]; ?><br/>

<br/>
<?php $assoc["first_name"] = "Larry";?><br/>
asociat cu Larry

-first name este

<?php echo $assoc["first_name"] ." ". $assoc["last_name"]; ?><br/>


<?php echo $?>

ARRAY FUNCTIONS
<html>
<head>
<title>ARRAY FUNCTIONS</title>
</head>
<body>
<?php $numbers = array(8,23,15,42,16,4); ?><br/>
Count:

<?php echo count($numbers); ?><br/>

Max value: <?php echo max ($numbers); ?><br/>


Min value: <?php echo min ($numbers); ?><br/>
<br/>
<pre>
Sort:

<?php sort($numbers); print_r($numbers); ?><br/>

Reverse sort: <?php rsort($numbers); print_r($numbers); ?><br/>


</pre>
</body>
</html>

You might also like