PHP strip_tags : Remove HTML markup from a string

December 10th, 2009 Shyju No comments

strip_tags is a PHP function which will remove all HTML mark up from a string.This will remove PHP tags and XML mark from the input string if there is any

Ex : $strPreviewName=’I am <b>Bold</b>and<i>Italic</i>’;

The output of echo $strPreviewName would show

I am Bold and Italic.

Now this would make problems in cases where u need to take a substring of the first string or trim the string to  take the first 50 characters .Then it would break the HTML markup and which will leads to the rest of the page contents to be affected by the styles mentioned in the first string. In this case,we can use strip_tags function to remove all HTML markups from the string.

Ex : $strPreviewName=’I am <b>Bold</b>and<i>Italic again</i>’;

$strPreviewNameUpdated =strip_tags($strPreviewName);

The output of echo $strPreviewNameUpdatedwould show

I am Bold and Italic.

Categories: PHP Tags:

SET NOCOUNT ON and SQL storded procedure performance

November 7th, 2009 Shyju No comments

SET NOCOUNT ON

When we run a Select /Insert/ Update or Delete statement against a DB table,we usually get a message like n rows affected .When we run the query in query analyzer for some manual debugging this message is quite helpful.But when u run the same query using a stored procedure,Why do we need this. Obviously this would be an overhead since it would take the network traffic too to convey this message back to the calle (From a DB server to the Data Access layer code) .Usage of SET NOCOUNT ON avoids this problem.It will stop sql server from sending this message back to the calle ,hence improve the performance.So its always a good practice to use SET NO COUNT ON in all your stored procedures to make your application more faster

Example

ALTER PROCEDURE SaveUserData(
@firstName nvarchar (50),
@lastName nvarchar (50),
@email  nvarchar(50))

AS
SET NOCOUNT ON

BEGIN
INSERT INTO USER_MASTER(FIRST_NAME,LAST_NAME,EMAIL) values (@firstName,@lastName,@email)

END

Official microsoft link

Categories: Misc Tags:

Get User desktop folder path in C#

July 16th, 2008 Shyju No comments

How to Get the Path to the User desktop in C#.NET ? Here is the single line Code

string strPath=Environment.GetFolderPath(System.Environ

ment.SpecialFolder.DesktopDirectory).ToString();

OUTPUT looks like this..

F:\Documents and Settings\Shyju\Desktop

Setting PATH while Installing an Application – Visual Studio 2005 Setup project

July 9th, 2008 Shyju 2 comments

A Small stuff to explain how to set the path variable for our executable’s Application folder.So that we can call the executable from anywhere in the PC ,(like invoking the notepad application from the PC,by command prompt).

Start……????????

Create a Project for Your Actual requirement.Write code for the functionalities u want to run when the user run the executable on the machine.Once You finish it,You can add a deployment Setup project to this project.for this Go to File->Add->New Project.Then a Dialog box will appear and from there we can select the Other Project types->Setup wizard.This Project will be added to the Available Project and Hence a Solution will be created and both of the projects will be comes under the Solution.

I hope you guys know how to Go ahead with the deployment creation wizard.very simple.Only thing u need to do is clicking the proper NEXT buttons !

Solution Explorer with 2 projects

Now When u build the Projects,You will get the Installable stuff.You can find this in your project’s(Deployment Setup project) Debug directory.The file name will be having an .msi extension.

Project Setup output

You can run this installer program in your pc and it will install our Application in it.

If you go to the Application folder ,You can see the executable there.

exe in progrm files

You can double click on the exe file to run it.

we can run the program from Commandprompt too.But for that we have to traverse through the folders using cd command.
Now we are going to make some changes to an environment variable for running our new executable.There is an environment variable called “Path” ,Where we will map some folder locations where the system has to search for some executables when a call for the exe comes.

for example,if we are typing notepad in command line, a new Notepad application will be launched.how it came ?Here comes the significance of “PATH”.The Full address of the notepad.exe has been mapped in the Path variable.so when the system get a call to the executable.It will look in to the Folders which are mapped in PATH.

Now we are going to Set the path for our exe in the system environment variable.
For that we will create another DLL and this dll will be called when the User installs our application

So we can add another project to our existing Solution.
File->Add->New Project
The newly added project too comes under solution explorer.Here we will add code to Set the path varaible value(our new appliacation folder location).In this we have to put the following code

// CODEpublic void SetPathVariable()
{
string[] cmd_args = System.Environment.GetCommandLineArgs();
AppendPathVariable(cmd_args[0]);
}
public void AppendPathVariable(string appPath)
{
try
{

string loc = GetPathOnly(appPath);
// System.Environment.SetEnvironmentVariable(“Path”, loc, EnvironmentVariableTarget.User);
string Value = System.Environment.GetEnvironmentVariable(“Path”, EnvironmentVariableTarget.Machine);
Value = Value + “;” + loc;
System.Environment.SetEnvironmentVariable(“Path”, Value, EnvironmentVariableTarget.Machine);

}
catch (Exception ex)
{
MessageBox.Show(“Omnex CRM found an Error in Setting the Environment variable\n” + ex.ToString());
}
}

// Function to Return the URL exclude the Application(exe) name
public string GetPathOnly(string url)
{
string outputStr = “”;
string ipurl = url;
char[] delimiter = { ‘\\’ };
string[] values = ipurl.Split(delimiter);
for (int i = 0; i < values.Length – 1; i++)
{
if (i == 0)
{
outputStr = values[i];
}
else
{
outputStr = outputStr + “\\” + values[i];
}
}
return outputStr;
}

private void Form1_Load(object sender, EventArgs e)
{
SetPathVariable();
this.Close();
}

//CODE ENDS

This part is over.from the code itself you would have understand what we are doing .
In the Form_Load ,we are calling the method SetPAthVariable().Let us check what is

inside SetPathvaraiable.we are reading the commandline arguments and passing the first
argument to another function called AppendPathVariable.Assume that the first argument
is having the full path to the exe with the executable name.Inside AppendPathVariable,we are caling GetPathOnly() for removing the executable name from the entire path.After that we are fetching the current Path variable then appending the New Path to It.Using the static method SetEnvironmentVariable(),we are setting the newly created path.

Now we have to Pass the Commandline arguments to this Program.For that we will use the custom action feature to our deployment Setup project
(Select the Project View->Editor->Custom Action).

Add Custom Action to Deployment Project

There will be for options such as Install,Commit,Rollback,UnInstall
Select Commit,Right click,Select Add custom action,Select the EXE where i have the code to set the path variable.

Add Custom Action
Click OK
Select the Newly added Exe from the list.Go to its properties,

Set the Installer class property to false.
Set the value of the ARGUMENTS property to

“[OriginalDatabase]<>[TARGETDIR]<>[ComputerName]“

custom Action Properties

Thats all here.
Then just build the Projects-Solution.Get the Latest msi files from the Debug folder of Deployment Setup project

Guys , try this .This was working for me.If you have any queries , Please let me know .Happy to help (with my little knowledge)….