To get full path to the script currently being read:
dirname(__FILE__)
To get just the current directory name:
basename(dirname(__FILE__))
To get full path to the script currently being read:
dirname(__FILE__)
To get just the current directory name:
basename(dirname(__FILE__))
Safe redirect:
<?php
function Redirect($Str_Location, $Bln_Replace = 1, $Int_HRC = NULL)
{
if(!headers_sent())
{
header('location: ' . urldecode($Str_Location), $Bln_Replace, $Int_HRC);
exit;
}
exit('<meta http-equiv="refresh" content="0; url=' . urldecode($Str_Location) . '"/>'); # | exit('<script>document.location.href=' . urldecode($Str_Location) . ';</script>');
return;
}
?>
As everyone should be aware, SimpleXmlElement class is not capable to preserve the indents in xml output.
To achieve that the DOMDocument class comes in handy.
//Format XML to save indented tree rather than one line and save
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
$dom->save('fileName.xml');
[abc] A single character: a, b or c
[^abc] Any single character but a, b, or c
[a-z] Any single character in the range a-z
[a-zA-Z] Any single character in the range a-z or A-Z
^ Start of line
$ End of line
\A Start of string
\z End of string
. Any single character
\s Any whitespace character
\S Any non-whitespace character
\d Any digit
\D Any non-digit
\w Any word character (letter, number, underscore)
\W Any non-word character
\b Any word boundary character
(…) Capture everything enclosed
(a|b) a or b
a? Zero or one of a
a* Zero or more of a
a+ One or more of a
a{3} Exactly 3 of a
a{3,} 3 or more of a
a{3,6} Between 3 and 6 of a
options: i case insensitive m make dot match newlines x ignore whitespace in regex o perform #{…} substitutions only once
Here is the simple piece of code to list all files in a given directory
//path to directory to scan
$directory = "../images/team/harry/";
//get all image files with a .jpg extension.
$images = glob($directory . "*.jpg");
//print each file name
foreach($images as $image)
{
echo $image;
}
<div id='div_id'> Blah! Blah! </div>
To set the div above to the center we can use next JQuery code.
jQuery.fn.center = function () {
var w = $(window);
this.css("position","fixed");
this.css("top",w.height()/2-this.height()/2 + "px");
this.css("left",w.width()/2-this.width()/2 + "px");
return this;
}
$("#div_id").center();
We have the html code below:
<select name="sel" id="sel"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select>
document.getElementById("sel").value = 3
or
function setSelectedIndex(s, v) {
for ( var i = 0; i < s.options.length; i++ ) {
if ( s.options[i].value == v ) {
s.options[i].selected = true;
return;
}
}
}
Coming soon!
?
$('input[type="radio"]').change(function() {
$(this).prop('checked', function(i, checked){
return !checked;
});
});
if(! move_uploaded_file($file['tmp_name'], $this->full_name ) )
throw new Exception("Error to save the file {$this->full_name}");
$oldumask = umask(0);
if( ! chmod( $this->full_name, 0755 ) )
throw new Exception("Error to set permissions for the file {$this->full_name}");
umask($oldumask);
<html>
<head>
<script type="text/javascript">
function load()
{
document.getElementById('select_id').value = 24;
}
</script>
</head>
<body onload="load()">
<h1>Hello World!</h1>
</body>
</html>
Code snippet to include JQuery UI framework from Google libs
<head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> </head>