PHP and Javascript Summary
PHP and Javascript Summary
Lists
<ul style="list-style-type:disc;"> <li> <العنصر االول/li> <li><الثاني/li> </ul>
<ol start=? ,type="1/A /a/I /i" > </ol>
<dl> <dt></dt> <dt></dt> </dl>
Forms
tables
<td></td>(cell)
</table>
javascript
(1)loops for (before loop; condition for loop; execute after loop) { what to do during the loop}
while Sets up conditions under which aloop executes do while — Similar to the while loop, however, it executes at least
once and performs a check at the end to see if the condition is met to execute again break Used to stop and exit the cycle at
certain conditions continue Skip parts of the cycle if certain conditions are met
(2)FUNCTIONS (methods)
alert() Output data in an alert box in the browser window confirm() Opens up a yes/no dialog and returns true/false
depending on user click console log() Writes information to the browser console, good for debugging purposes
document.write() Write directly to the HTML document prompt() Creates an dialogue for user input decodeURI() Decodes
a Uniform Resource Identifier (URI) createdby encodeURI or similar decodeURIComponent() Decodes a URI component
encodeURI() Encodes a URI into UTF-8 encodeURIComponent() Same but for URI components eval() Evaluates
JavaScript code represented as a string isFinite() Determines whether a passed value is a finite number isNaN() Determines
whether a value is NaN or not Number() Returns a number converted from its argument parseFloat() Parses an argument
and returns a floating point number parseInt() Parses its argument and returns an integer addeventlistener(‘click’,’function’)
arrays
concat() Join several arrays into one index Of() Returns the primitive value of/the specified object join() Combine elements
of an array into a single string and return the string last Index Of() Gives the last position at which a given element appears
in an array pop() push() Add a new element at the end reverse() shift() Remove the first element of an array slice() Pulls a
copy of a portion of an array into a new array sort() Sorts elements alphabetically splice() Adds elements in a specified way
and position to String() Converts elements to strings value Of() Returns the first position at which a given element appears
in an array
Strings
trim() //is an instruction to remove any spaces or other white spaces in the string
password_hash($pass,PASSWORD_DEFAULT) //convert the password entered by the user into a secure password
charAt() Returns a character at a specified position inside astring concat() Concatenates (joins) two or more strings into one
indexOf() Provides the position of the first occurrence of a specified text within a string lastIndexOf() search() Executes a
search for a matching text and returns its position slice() Extracts a section of a string and returns it as a new string split()
Splits a string object into an array of strings at aspecified positionsubstr() Similar to slice() but extracts a substring
depended on a specified number of characters toLowerCase() toUpperCase()
Numbers
toExponential() toFixed() Returns the string of a number with a specified number of decimals toString() abs(x)
Returnsabsolute value of x floor(x) biggest whole num <=n log(x) max(x,y,z,...,n) min(x,y,z,...,n) pow(x,y) X to the
power of y random() Returns a random number between 0 and 1 round(x) The value of x rounded to its nearest integer
sin(x) sqrt(x) tan(x) acos(x) asin(x) atan(x) cos(x) exp(x)
DATES NOW() date now
Date() Creates a new date object with the current date and time Date(2017, 5, 21, 3, 23, 10, 0) Create a custom date object.
The numbers represent year, month, day, hour, minutes, seconds, milliseconds. Date("2017-06-23") Date declaration as a
string getDate() Get the day of the month as a number (1 31) getDay() The weekday as a number (0-6) getFullYear()
getHours() Get the hour (0-23) getTime() Get the milliseconds since January 1, 1970 of 13 24 getUTCDate() setDate()
Set the day as a number (1-31) setFullYear() Sets the year (optionally month and day) setHours() Set the hour (0-23)
setTime() Set the time (milliseconds since January 1, 1970) setUTCDate() Sets the day of the month for a specified date
according to universal time (also available for day, month, fullyear, hours, minutes etc.)
Nodes
appendChild() Adds a new child node to an element as the last child node cloneNode() Clones an HTML element
compareDocumentPosition() Compares the document position of two elements hasChildNodes() isDefaultNamespace()
Returns true if a specified namespaceURI is the default isEqualNode() Checks if two elements are equal isSameNode()
Checks if two elements are the same node isSupported() Returns true if a specified feature is supported on the element
normalize() Joins adjacent text nodes and removes empty text nodes in an element removeChild() replaceChild()
getAttribute() Returns the specified attribute value of an elementnode getAttributeNode() Gets the specified attribute node
with the given namespace and name getElementsByTagName() Provides a collection of all child elements with the
specified tag name getElementsByTagNameNS() Returns a live HTMLCollection of elements with a certain tag name
belonging to the given namespace hasAttribute() removeAttribute() setAttribute() Sets or changes the specified attribute to
a specified value
Window
alert() Displays an alert box with a message and an OK button blur() Removes focus from the current window
clearInterval() Clears a timer set with setInterval() close() Closes the current window confirm() Displays a dialogue box
with a message and an OK and Cancelbutton focus() Sets focus to the current window moveBy() Moves a window relative
to its current position moveTo() Moves a window to a specified position open() Opens a new browser window print()
Prints the content of the current window prompt() Displays a dialogue box that prompts the visitor for input resizeBy()
Resizes the window by the specified number of pixels resizeTo() Resizes the window to a specified width and height
scrollBy() Scrolls the document by a specified number of pixels scrollTo() Scrolls the document to specified coordinates
setInterval() Calls a function or evaluates an expression at specified intervals stop() Stops the window from loading closed
Checks whether a window has been closed or not and returns true or false defaultStatus Sets or returns the default text in the
statusbar on a window document Returns the document object for the window frames Returns all <iframe> elements in the
current window history Provides the History object for the window innerHeight The inner height of a window’s content
area innerWidth The inner width of the content area length Find out the number of <iframe> elements in the window
location Returns the location object for the window name Sets or returns the name of a window navigator Returns the
Navigator object for the windowopener Returns a reference to the window that created the window outerHeight The outer
height of a window, including toolbars/ scrollbars outerWidth The outer width of a window, including toolbars/ scrollbars
pageXOffset Number of pixels the current document has been scrolled horizontally pageYOffset — Number of pixels the
document has been scrolled vertically parent The parent window of the current window
screen
screen Returns the Screen object for the window screenLeft The horizontal coordinate of the window (relative to screen)
screenTop The vertical coordinate of the window screenX Same as screenLeft but needed for some browsers screenY
Same as screenTop but needed for some browsers status Sets or returns the text in the statusbar of a window top Returns
the topmost browser window Screen Properties colorDepth Returns the bit depth of the color palette for displaying images
height The total height of the screen pixelDepth The color resolution of the screen in bits per pixel width The total width
of the screen
(3)events & actions bind unbind die live off on one triggerhandler undelegate blur change focus
focusin out select submit keyword keypress keyup click contextmenu dblclick mousedown mouseenter mouseleave
mousemove mouseout mouseover mouseup toggle .animate({styles},speed,easing,callback)
.clearQueue() .delay(speed,queueName) Sets a delay for all queued functions on the selected elements
.fadeIn(speed,easing(swing,linear),callback الداله اللي هتتعمل تالشي.fadeOut() .fadeTo(speed,opacity (number
between 0.00 and 1.00 ),easing,callback) Fades in/out the selected elements to a given opacity
.fadeToggle(speed,easing,callback) التبديل بين االتنين.hide(speed,easing,callback) Hides the selected elements .finish
() .show() Shows the selected elements slidedown() slideUp() slideToggle() stop() toggle() Toggles between the hide() and
show() methods addclass (classname,function(index,currentclass) ) after(content,function(index)
append(content,function(index,html)insert content attr(attribute ) insert att
(4)traversing actions
add() add element to set of matched elements children()returns all direct chidren of selected element closest () return
ancestor of the ele filter find() descendant eles of ele has(0 returns all eles that has ele inside it next() sibling
ajax exchanging data with the server
variable=new XMLHttpRequest(); //create http request object
xml.httprequest.method() or property
xhttp.open(“get”,file name,true)
xhttp.send()
(2)Properties
onreadystatechange defines afunction to be called when readystate property changes readystate holds status of
xmlrequest (0 req not initialized/1 connection established/ 2 req received/ 3 processing req 4 req finished )
responsetext returns response data as string responsexml returns response data as xml data status return status
number of a request (200 ok/ 403 forbidden /404 not found ) statustext returns the status-text (ok.notfound
colors .text-muted .text-primary sucsses info warning danger secondary white dark light
.bg-primary tables .table-striped .table-bordered .table-hover .table-dark .table-borderless .table-(primary sucsses info
warning danger secondary white dark light) .table-sm(small) .table-responsive image rounded .rounded-circle .img-
thumbnail .mx-auto (margin auto) .d-block(disblay block) img-fluid alert alert-(primary sucsses info warning danger )
button btn btn-(primary sucsses info warning danger secondary white dark light) outline lg(large) sm(small) blick active
disabled btn-groub -(primary sucsses info warning danger secondary white dark light) btn-groub-vertical spinner
spinner-(border grow ) text-(primary sucsses info warning danger secondary white dark light) pagenation ul active
disabled pagination-(ld sm) list groub ul active disabled list-groub-flush(remove borders) -horizontal list-group-item-
(primary sucsses info warning danger secondary white dark light) dropdown-menu dropdown-divider dropdown-
header dropdown-item active dropright dropup form form-group form-inline form-check-input form-control form-
check-inline form-control-sm-lg card(img) card-body card-title card-subtitle card-text card-link card-img-top middle
image card-img-bottom card-img-overlay list-group card-header card-footer card-group card-deck card-columns
jumbotron(div) jumbotron-fluid
php
upload_max_filesize()
$varname $arrname=array(…,..,..)
require_once(“file-name”) // include file
var = $_post[‘text-box-name’] // store data from text box into the var
define(‘constant-name’,value); //constant
class class-name{….}
class-name→attribute // accessing
class-b extends class-a {…..} // inheritance
include() function
$errors = array(); // Initialize an error array
Functions
echo print
$data=file_get_contents(“url”) get data from url to new variable
Array count() sort() isset() sizeof() isset() عنصر موجود وال الarray_push(arrname,element)
array_search(arrname,element) مكان العنصرarray_diff (arr1, arr2)بيطلع المختلف بينهم/ unset(element) بيحذف
العنصرarray_reverse() array_merge() array_sort()ترتيب بالبجدي
Date and Time date (format, timestamp) mktime (hr, min, sec, month, day, yr) strtotime (str) time ()
Standard isset(el) print(str) time() date(format, time) mt rand(min, max) header(string) die(message) include(path) JSON
json_encode(obj) json_decode(string) Session and Cookie setcookie(name, val, expiration) session_start()
session_destroy() session_regenerate_id(del ID) Cookies setcookie Sessions session_start() session_destroy()
session_cache_expire(<0-9>) session_cache_limiter() session_decode() session_encode(); session_id([])
file $fb=fopen(filename,rb/’w’) open file to read or write fhtmlspcialcharacters(fgets($fb)
file_exists(“file-name”) unlink() delet file flock() locking file $_files[‘file-name’][‘name/size/type/tem_name’] name of
the uploaded file-name/ size/type move_uploaded_file(‘$tem_name’,’$location’) copy() delet() filetype() file()
sql
create table table-name (column-name colomn-type)
insert into table-name(field1,field2,..)values(value1,value2,…)
select field1,field2,.. from table1,table2,… where condition1 and/or condition2 //fetch data from the db
update table-name set field1=new-value , field2=new-value
c#
using keyword is uesed to include namespaces in the program
datatype variablenames; //define variable
data-type [] array-name= {elements}
switch (expression){case value1: //statments break; case value2: break;}
access-modifier return-type method-name([parameters]){bodyofthemwthod}
class-name object-name = new class-name (parameter list)
puplic private protected internal protectedinternal (encapsulation)
struct structure-name {} //strctute used to represent a record kind of class not support inheritance
enum enum-name{sun,mon,tues} ; //enum is set of integers constants have the arrangment order
access-specifier class class-name {member variables, member functions} //class declaration
constructor is special function to make new objects from the class have the same name ass the class ~ destructor
class derieved-class : base-class{….} inheritance
overload : some methods with the same name different data types
abstract classname {} ; // polymorphism same method names same parameters but diffirent data types cannot make an
instance of abstract class
interface interface-name {….} //parent class contains methods donnot have parameters
namespase name{…} // used to keep set of names separte from others
try{code catch(exception name e1){code}catch(..){...}finally{...}}
(1)functions
console.readline(“”) take input from the user console.writeline(“”) string concat(..,..) contains(string value)
copy(string str) endwith() equals() toupper()
json
json.function()
localstorage.setitem(file-name,json-object) //store json object as text
localstorage.getitem(file-name) //text to java object
{“name”:”mo”} name value pair
{obj-name:{name value pair,namevalue pair}}
json_encode(obj) //php
functions stringify(obj) convert all obj elements to strings parse data from json format to javascript objecr
node js
module is like js library
exports.mydatatme=function(){instructions} // creat module thst do this instructions
var http =require(‘http’) // include http module built in module
var dt = require(‘./module-location’) include made module
http.creatserver(function(req,res){res.write(…) res.end;}) //http module makes http server that listens to server ports
res.writehead(200,{‘content-type’:’text/html}) //add http header
fs.readfile() //method to read files in the computer
fs.appendfile(filename,…..) //appends specific content to a file
fs.open(‘filename’.’w’) //openfile writes in it
fswritefile(‘file-name’,’helloworld’) // writes something in a file-name
fs.unlink(‘file-name’) // deletes spscific file
fs.rename()
require(‘url’) // include url module-l
url.parse() //return url object
require(‘upper-case’) // include upper case package
http.listen(3000) //start it up on port 3000
functions
setimeout() excute function after time delay
cleatimeout(0
setinterval()
clearinterval()
window object. function()
var st =require(“./filename”)
\console.log() console.error() console.warn()
node js package manager
-------------------------------------------------------
syntax
modules functions checks
console.log(__dirname); بيحدد الديركتوري اللي حطيت الكود فيها
بيديني المسار بتاع الفايل
console.log(__filename) مكان الفايل
console.log(os.freemem) free memmory
console.log(os.homedir)
wordpress themes
wp_headtag () puts additional info in the head tag