Hi everybody. After a long time, I am here again with my new articles. I thought it can be good to start with a little clue for PHP coders.
Usage of PHP functions is so easy and practical. However, usually we need to write our own functions while we are making our applications.
1.1) User Defined Functions in PHP
Structure 1.0:
1 2 3 4 5 6 7
| <?php
function FunctionName( arguments ){
//php codes
}
?> |
The function ends when return() statement is executed. Click to Read Complete Article »
We have talked about how to make database connections in PHP before. However, I realized that I have forgotten something which is so important. If you read that article or you are interested in PHP, you may know that we use odbc_connect() or mysql_connect() (or etc.) functions to connect some databases. These functions try to connect to specified databases. I wish every request would be accepted, because it is possible getting errors during the process. If the connection is not successful, the rest of codes will not work properly. So today, I will show you how to check database connections.
It is so simple checking database connections in PHP. We need to know that Click to Read Complete Article »
Today, we are going to talk about getting content of PDF documents. In addition, PDF is a document format of Adobe Acrobat developed by Adobe and abridgment of Portable Document Format. After giving this unnecessary information, let’s learn how to read PDF documents using PHP.
To open and read PDF documents via PHP, we need to use a package: TCPDF plug-in for reading PDF.
Reading and Modifying Content of PDF
You can download TCPDF package from here. This is a free package and you can use it easily. There are some examples from tecknick that show how to use this package:
Example 1.0: Creating a Simple PDF Document.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| <?php
require_once('../config/lang/eng.php');
require_once('../tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 002');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', 'BI', 20);
// add a page
$pdf->AddPage();
// print a line using Cell()
$pdf->Cell(0, 10, 'Example 002', 1, 1, 'C');
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_002.pdf', 'I');
?> |
Click to Read Complete Article »
If you used DOCTYPE in your pages, you may be in trouble with changing scrollbar color and style. Web developers usually define scrollbar properties in body tag in CSS. However, if you used DOCTYPE this is not going to work. All you need to do, defining scrollbar style in HTML tag in CSS file, and… Yes, that’s all!
Wrong Usage: Style.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| body{
/*
Your other body style properties…
*/
scrollbar-base-color: #C1CBD7;
scrollbar-arrow-color: #9DACBF;
scrollbar-3dlight-color: #C1CBD7;
scrollbar-darkshadow-color: #C1CBD7;
scrollbar-face-color: #C1CBD7;
scrollbar-highlight-color: #C1CBD7;
scrollbar-shadow-color: #C1CBD7;
scrollbar-track-color: #FFFFFF;
} |
Click to Read Complete Article »
We may need to use shadows behind objects in some cases on our web sites; but browsers don’t support all shadow codes. It is possible to see the same page with different appearances via different browsers. So, we found a little solution for that.
PNG files are going to be used for giving shadow effect to elements, because PNG format gives us lots of advantages and one of them is opacity. Make a shadow image and set size of it as you want. We made a PNG file and you can download it from here.
CSS File: Style.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| div.shadowbox {
padding: 0;
float: left;
display: block;
position: relative;
margin: 6px 0px 0px 6px !important;
background: url(img/shadow.png) no-repeat bottom right !important;
}
div.shadowbox ELEMENT{
margin: -6px 6px 6px -6px;
position:relative;
display:block;
} |
Simply, we made Click to Read Complete Article »
Hi again! Today, I’m going to give you a JAVA function that uppercases first letters of each word, sentence or line. This function is also very similar with the function which was given at this article: Making uppercase the first letters of words, sentences and lines in ASP. To understand the algorithm, take a look that.
I will name my function UppercaseTheFirstLetter() again. I like that.
Function 1.0: public static String UppercaseTheFirstLetter(String string, int option)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public static String UppercaseTheFirstLetter(String string, int option){
String splitby = null,uppercased=null,output=null;String[] parts;int i; //Variables are defined
if(option==0){splitby=" ";}
else if(option==1){splitby="\\.";} //to define the dot string we used 2 backslashes.
else if(option==2){splitby="\n";} //to define new line string we used \n
string=string.trim ();
parts = string.split(splitby);
for(i=0;i<parts .length;i++){
parts[i]=parts[i].trim();
if(parts[i].length()>0){
uppercased=parts[i].substring(0,1).toUpperCase()+parts[i].substring(1,parts[i].length());
if(i>0){
output+=splitby.replace("\\", "")+uppercased;
//if splitby criteria is a dot we need to clear the backslash \.
}else{
output=uppercased;
}
}
}
return output;
} |
This function is an avoid function that makes the first letters of all separated words, sentences or lines uppercased, then
Click to Read Complete Article »
Arrays are one of the basics of programming. We can create lots of things via arrays like matrices, databases, tables… Let’s make it shorter and start.
Array() Function in ASP
We define our arrays using the Array() function. We can store values with two different ways. We can create the array and put values in array at the same time, or we can create the array then we can initialize the values. For getting the values from arrays we have to know position of value in array. For example; second value of array, third value of array, 56th value of array etc. There is very important point that you have to know: Array() function is zero based. That mean’s first value of array is the 0th element of array.
1.1) Fixed Size Arrays
It’s better to use this usage, if you know exactly number of elements which will be used, because the compiler will know the size of array and make the processes faster.
Example 1.0: Creating the array and initializing the values at the same time.
1 2 3 4 5 6 7 8 9
| < %
dim my_array
my_array=Array("First","Second","Third","Fourth")
Response.Write "my_array(0) : "&my_array(0)&"<br/>"
Response.Write "my_array(1) : "&my_array(1)&"<br />"
Response.Write "my_array(2) : "&my_array(2)&"<br />"
Response.Write "my_array(3) : "&my_array(3)
%> |
Output of Example 1.0:
1 2 3 4
| my_array(0) : First
my_array(1) : Second
my_array(2) : Third
my_array(3) : Fourth |
This is a fixed array that includes only 4 elements that you define. You can not add another element in this array. Also, Click to Read Complete Article »
We have talked about making uppercase the first letters of words, sentences and lines in ASP before. Now, we will make the same application in JavaScript.
Let’s look at the UppercaseTheFirstLetter() function.
Function 1.0: UpperFunction.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function UppercaseTheFirstLetter(string,option){
var splitby,parts,i,uppercased;
if(option==0){splitby=" ";}
else if(option==1){splitby=".";}
else if(option==2){splitby="<br />";}
string=string.replace(/^\s+/, '').replace(/\s+$/, '');
//we removed unnecessary spaces at the beginning and ending of string.
parts = string.split(splitby);
for(i=0;i<parts .length;i++){
parts[i]=parts[i].replace(/^\s+/, '').replace(/\s+$/, '');
if(parts[i].length>0){
uppercased=parts[i].slice(0,1).toUpperCase()+parts[i].slice(1,parts[i].length);
if(i>0)output+=splitby+uppercased; else output=uppercased;
}
}
return output;
} |
This function is an avoid function that makes the first letters of all separated words, sentences or lines uppercased, then Click to Read Complete Article »
There is a list of all operators in C.
- Assignment Operator
- Arithmetic Operators
- Cast Operator
- Increment and Decrement Operators
- Abbreviated Assignment Operators
- Relational Operators
- Logical Operators
- Precedence of Operators
I. Assignment Operator
Equal sign (=) is used as assignment operator in C and it must be read as “is assigned the value of”.
That means: a is assigned value of b. There is also this usage that allows you to make multiple assignments like this:
All of the variables are equalized to 153. The precedence of assignment operator is right to left. That means first o is equalized to 153, then c is assigned value of o which is 153, finally r is assigned value of c. Click to Read Complete Article »
Functions are generally used to perform same operations, or compute equations. For example, suppose that you need to get an average of some numbers. What do you have to do? Are you going to write the equations all the time? A good programmer has to find the shortest way to do works. So, if we always need to get average of numbers, we write a function that evaluates average of numbers instead of writing equations for each operation. That’s why, we need functions, and that’s why you have to know how to use functions.
A function works in two different ways. It can return a value or it can do just operations. If the function makes only operations, doesn’t return a value then it is called void function, else it is called avoid function.
We use function procedure to create functions in ASP.
1.1 ) Making Avoid Functions in ASP
Structure 1.0: Structure of an avoid function in ASP
1 2 3 4 5 6 7 8 9
| < %
function FunctionName( arguments )
'…
'Operations
'…
FunctionName=value
end function
%> |
Click to Read Complete Article »
One of the most disturbing problems of webmasters is users which have no idea about typing a sentence. It’s should be so difficult for website owner’s to see, some silly sentences typed incorrectly on their well-designed and good-looking websites. As we all know each word of titles, names and surnames or the first letter of a sentence ALWAYS start with an uppercase letter. Unfortunately there is no such rule in caveman literature. They write the first letters of sentences or their first letter of their names small. However, you don’t need to get angry anymore. There is a little solution for these cavemen. We are going to write a function that will change first letters of each word in a sentence or the first letter of a sentence. It means, we will set the cavemen’s sentences in a correct sentence format. Also, we can convert the first letter of lines to uppercase. This can be useful when you write a poem, lyric or something like that. Let’s begin.
Firstly, there is our UppercaseTheFirstLetter() function then we will clarify it with examples.
Function 1.0: No Cavemen No Cry
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| < %
function UppercaseTheFirstLetter(string, object)
if object=0 Then 'if first letter of words in sentence must be uppercased.
splitby = " "
elseif object=1 Then 'if first letter of sentence must be uppercased.
splitby = "."
elseif object=2 Then 'if first letter of a new line must be uppercased. (ie: poem, lyric etc.)
splitby = "<br>"
end if
'These keywords can be changed or added manually.
string=trim(string) 'we removed unnecessary spaces at the beginning and ending of string.
parts = Split(string,splitby) 'string is split by our intercept criteria.
'parts is an array that contains each piece of divided string.
for fi=0 to uBound(parts) 'loop 0 to size of parts array.
the_part=trim(parts(fi)) 'we removed extra spaces at the beginning and ending of part.
if len(the_part)>0 Then 'if the part is not null or not space.
uppercased = ucase(mid(the_part,1,1))&mid(the_part,2,len(the_part)-1)
'The first letter of the_part is taken and converted to uppercase,
'Rest of the_part is added at the end of the letter.
if fi>0 then output=output&splitby&uppercased else output=uppercased'string is gathered again.
end if
next
UppercaseTheFirstLetter=output
end function
%> |
Click to Read Complete Article »
We need to know how to use properties and methods of Navigator object in JavaScript to make powerful applications. Navigator object gives us to get browser information of client. There is a list of all properties and methods in Javascript.
I. All Common Navigator Properties in JavaScript
|
Property
|
Description
|
|
appCodeName :
|
The code name of the browser (ie: Mozilla)
|
|
appName :
|
The name of the browser (ie: Netscape)
|
|
appVersion :
|
The version information of the browser (ie: 5.0 (Windows; en))
|
|
mimeTypes :
|
Returns array of all MIME types supported by the client
|
|
platform :
|
Returns the platform of visitor’s computer (ie: Win32)
|
|
plugins :
|
Returns array of all plug-ins which is installed on visitor’s computer
|
|
userAgent :
|
Returns the user-agent header (ie: Mozilla/5.0 (Windows; U; Windows NT 6.0; tr; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729))
|
|
onLine :
|
Returns bolean value of browser’s online status (ie: true)
|
|
cookieEnabled :
|
Returns bolean value of browser’s cookie status (ie: false)
|
|
cookieEnabled :
|
Returns bolean value of browser’s cookie status (ie: false)
|
Click to Read Complete Article »
Using databases gives us lots of advantages. Listing and paging our records dynamically is one of them. In our applications, we may need to show so many records to user and in order to make it clear we have to list them well-arranged. However, listing too many database records in one time can be a handicap for us, because if the number of records reaches the huge values, then loading pages takes long time. So, we should separate records to pages. It means that in respect of number of database records, pages will be created automatically and a specified number of records will be shown on each page.
We have to know some paging and listing statements to do this issue. There are some paging and listing statements which will be used in this article.
Paging Statements
- PageSize is used to define limit number of records which will be shown in each page.
- AbsolutePage is used to determine the page selected.
- PageCount is used to get number of pages created automatically.
Listing Statements
- Move(X) is used to get Xth record from current record.
- MoveNext is used to get the next record.
- MovePrevious is used to get the previous record.
- MoveLast is used to get the last record.
- MoveFirst is used to get the first record.
There is also RecordCount statement for getting number total records Click to Read Complete Article »
1.1) MYSQL Connection in PHP
We can use mysql_connect and mysql_select_db functions to create our connections. For closing the connections there is mysql_close function. These are basic functions of managing connections in PHP. There are also a lot of classes made by developers for free.
Sturcture 1.0:
1 2 3 4 5
| <?php
$ConnectionName = mysql_connect('MyHost', 'MyLogin', 'MyPassword');
$DatabaseConnection = mysql_select_db('MyDatabaseName', $ConnectionName);
mysql_close($ConnectionName);
?> |
You can determine the
MyHost,
MyLogin,
MyPassword and
MyDatabaseName variables as you need.
Example 1.0: We used hostname:port syntax Click to Read Complete Article »
1.1) MSSQL ( Microsoft SQL Server ) Connection in ASP
Sturcture 1.1:
1 2 3 4
| < %
Set ConnectionName=Server.CreateObject("Adodb.Connection")
ConnectionName.Open "driver={SQL Server};server=MyHost;uid=MyLogin;pwd=MyPassword;database=MyDatabaseName"
%> |
You can determine the server, uid, pwd and database variables as you need.
Example 1.1:
1 2 3 4
| < %
Set MyConn=Server.CreateObject("Adodb.Connection")
MyConn.Open "driver={SQL Server};server=127.0.0.1;uid=memisologin;pwd=memiso;database=memisodb"
%> |
1.2) MDB ( Microsoft Access Database ) Connection in ASP
Click to Read Complete Article »
Recently Typed