Monday, September 10, 2007

How to display only a set number of words from a paragraph with asp?

Here is the simple code to display a set number of words from a long paragraph...

Dim shortdesc, index, strText
strText = "How to display only a set number of words from a paragraph with asp. How to display only a set number of words from a paragraph with asp. How to display only a set number of words from a paragraph with asp. "

strText=Replace(strText," "," ")

for index =1 to len(strText)
if mid(strText,index,1)= " " then
words = words+1
end if

if words=24 then
shortdesc = left(strText,index)
end if

next
Response.write shortdesc

Error trapping in asp

On Error Resume Next

The above line turns on VBScript error trapping. In doing so, whenever a line of script produces an error the processing continues on to the next line of the script.


If err.Number <> 0 Then
Response.Write err.Number &
Response.Write err.Description
Response.Write err.Source
err.Clear

how to get url with the help of server variable

$domain = $_SERVER['HTTP_HOST'];
// find out the path to the current file:
$path = $_SERVER['SCRIPT_NAME'];
echo $path;
$url = "http://" . $domain . $path ;

Date Difference in PHP

The date format shud be in mm/dd/yyyy

function dateDiff($dformat, $endDate, $beginDate){$date_parts1=explode($dformat, $beginDate);$date_parts2=explode($dformat, $endDate);$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);return $end_date - $start_date;}