Skip to main content

Posts

Showing posts from May, 2010

Javascript function to trim a string to remove the unwanted spaces before and after the string

JS function to remove unwanted spaces before and after a string

following function takes a string as input, replaces all concurrences of spaces before and after the string with a null values and returns the trimmed string.


//JS Function to trim a string:

functionJSTrim( str ){
//trimming the leading and trailing spaces of the input string.
return( str.replace(/^\s+/,'').replace(/\s+$/,'') );
}




JS function to remove multiple spaces in the string with a single space

We can alter the same function so that I removed the space before and after the string and also removes multiple spaces in the string with a single space.


//JS Function to trim a string:

functionJSTrim( str ){
//replacing the multiple spaces with single space
str = str.replace(/ +/g, " ");

//trimming the leading and trailing spaces of the input string.
return( str.replace(/^\s+/,'').replace(/\s+$/,'') );
}

Usage:

==========

var str = " My test              string "
document.write(…

PDF generation in PHP

There are several ways to generate PDF files using PHP

OPTION #1

One of the most adorable features of PHP 4 is the PDFLib extension, which allows you to dynamically construct PDF documents in Adobe Portable Document Format. For this you must have the PDFLib library installed on your system. If you're working on Linux, you can download a copy from http://www.pdflib.com/ and compile it for your box.

If you're running Windows,a pre-built PDF library is bundled with your distribution, and all you need to do is activate it by uncommenting the appropriate lines in your PHP configuration file.

In addition to this a PDF viewer application like Adobe PDf reader must be installed in your machiine to view the PDF file.

More on PHPLib Extension



OPTION #2
Another option is to use the PDF genertion Class files available as opensources.

Example:

1. FPDF
2. TCPDF
3. MPDF




FPDF CLASS

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from…

Apache crashed while connecting to MYSQL

I had installed latest WAMP and tried to load a php page which uses a class file.
the class file has code to connect to the Db for fetching records.
When ever the script attempts to make a connection i got the following Error
Window popup in IE and I am not able to do any DB related operation.

Code Sample
-----------------------------------------------------------------
function mysqlConnect(){
//Using Nonpersist connection
$this->_connection=@mysql_connect($this->str_dbServer, $this->str_dbUname, $this->str_dbPass) or $this->returnError("Unable to connect to Database server");
//Using Persist Connection

@mysql_select_db($this->str_dbName,$this->_connection); //Selecting DBASE
}



function mysqlDisconnect(){
// Disconnect the database after dbase access
@mysql_close();
}
----------------------------------------------------------------

How can this be solved?

This is the Err popup message tha…


Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »
Member
Search This Blog