Posted by: prajapatinilesh | May 16, 2012

truncate description — php read more link

These are some solutions to provide read more link using PHP
<?php

1)

// strip tags to avoid breaking any html
$string = strip_tags($string);
if (strlen($string) > 500) {
// truncate string
$stringCut = substr($string, 0, 500);
// make sure it ends in a word.
$string = substr($stringCut, 0, strrpos($stringCut, ‘ ‘)).’… <a href=”full link of read more page”>Read More</a>’;
}
echo $string;

2)

$num_words = 500; $words = array();
$words = explode(” “, $original_string, $num_words);
$shown_string = “”;
if(count($words) == 500){
$words[499] = ” … “;
}
$shown_string = implode(” “, $words);

3)

list($output)=explode(“\n”,wordwrap(strip_tags($str),500),1);
echo $output. ‘ … <a href=”#”>Read more</a>’;

4)

function split_words($string, $nb_caracs, $separator){
$string = strip_tags(html_entity_decode($string));
if( strlen($string) <= $nb_caracs ){
$final_string = $string;
} else {
$final_string = “”;
$words = explode(” “, $string);
foreach( $words as $value ){
if( strlen($final_string . ” ” . $value) < $nb_caracs ){
if( !empty($final_string) )
$final_string .= ” “;

$final_string .= $value;
} else {
break;
}
}//End of foreach( $words as $value )
$final_string .= $separator;
}
return $final_string;
}//End of function split_words

?>

Thanks, Nilesh.

Advertisements
Posted by: prajapatinilesh | May 14, 2012

jquery cross domain ajax request using JSON

// Include jquery library. <script src=”jquery file path”>

<div id=”facebook_feed_display_div” style=”height:300px;width:420px;overflow:auto;”></div>

<script>
function callFacebookFile() {
$(“#facebook_feed_display_div”).html(‘<span style=”color:red;font-size:13pt”>Loading Please Wait….!</span>’);

var urlFacebookCall = ‘http://different_server_url/facebook_call.php&#8217;;

var parameterString = ‘facebookAccountId=<?=$facebookAccountId?>’;
parameterString += ‘&param2=<?=$param2?>’;

/*var url = urlFacebookCall+”?facebookAccountId=<?=$facebookAccountId?>&&jsoncallback=?”;
$.get(url, function (data) {
$(“#facebook_feed_display_div”).html(data.msg);
}, ‘json’);*/

$.getJSON( urlFacebookCall+”?facebookAccountId=<?=$facebookAccountId?>&jsoncallback=?”,function(data) {
$(“#facebook_feed_display_div”).html(data.msg);
});

}//End of function callFacebookFile

callFacebookFile();
</script>

//———————————————————————————

//facebook_call.php into diff server.

$array = array(“msg”=>”hello”); //some bogus data
echo $_REQUEST[‘jsoncallback’].”(“.json_encode($array).”)”;
return;

Posted by: prajapatinilesh | May 14, 2012

jquery ajax call

// Include jquery library. <script src=”jquery file path”>

<div id=”facebook_feed_display_div” style=”height:300px;width:420px;overflow:auto;”></div>

<script>
function callFacebookFile() {
$(“#facebook_feed_display_div”).html(‘<span style=”color:red;font-size:13pt”>Loading Please Wait….!</span>’);

var urlFacebookCall = ‘facebook_call.php’;

var parameterString = ‘facebookAccountId=<?=$facebookAccountId?>’;
parameterString += ‘&param2=<?=$param2?>’;

$.ajax({
url:”facebook_call.php?facebookAccountId=<?=$facebookAccountId?>&param2=<?=$param2?>”,

//url: urlFacebookCall,
//data: parameterString,

success:function(result) {
$(“#facebook_feed_display_div”).html(result);
},
error: function (xhr, status, error) {
//alert(xhr.status);
//alert(xhr.responseText);
//alert(error);
}
});
}//End of function callFacebookFile

callFacebookFile();
</script>

Posted by: prajapatinilesh | April 30, 2012

embed tag is not playing songs

use height=”1″ , instead of height=”0″ to work into all browsers.

< embed src=”path of mp3 audio file” autostart=”true” width=”0″ height=”1″  id=”song_1″ enablejavascript=”true” >

Posted by: prajapatinilesh | April 30, 2012

Cross – Browser addEvent function.

function addEvent(evnt, elem, func) {
   if (elem.addEventListener)  // W3C DOM
      elem.addEventListener(evnt,func,false);
   else if (elem.attachEvent) { // IE DOM
      elem.attachEvent(“on”+evnt, func);
   }
   else { // No much to do
      elem[evnt] = func;
   }
}

Internet Explorer (up to version 8) used an alternate attachEvent method.

Internet Explorer 9 supports the proper addEventListener method.

Posted by: prajapatinilesh | August 8, 2011

JAIN SONGS LYRICS – tu mane bhagwan ek vardaan aapi de !!

I like this song very much.  so, adding its lyrics here.

[tu mane bhagwan ek vardaan aapi de
jya vase che tu mane tya sthaan aapi de]…(2)

[hu jivu chu ae jagat ma jya nathi jeevan
zindagi nu naam che bas boj ne bandhan]…(2)

[aakhri avtaar nu mandaan bandhi de
jya vase che tu mane tya sthaan aapi de]…(2)

[tu mane bhagwan ek vardan aapi de
jya vase che tu mane tya sthaan aapi de]…(1)

[aa bhoomi ma khoob gaaje paap na padgham
besuri thai jayi amari punya ni sargam]…(2)

[dil rubana taar nu bhangan saandhi de
jya vase che tu mane tya sthaan aapi de]…(2)

[tu mane bhagwan ek vardaan aapi de
jya vase che tu mane tya sthaan aapi de]…(1)

[jo vatan ma jya Lagi che sau kare shoshan
jom a jata koi ahiya na kare poshan]…(2)

[matlabi sansar nu jo daan kaapi de
jya vaseche tu mane tya sthaan aapi de]….(4)

tu mane bhagwan ek vardaan aapi de
[jya vaseche tu mane tya staan aapi de]…(4)
Thanks,
Nilesh Prajapati.
Posted by: prajapatinilesh | January 7, 2011

PHP Date ( Archived date list )

<?php
$stDtTimeVar = ’12/30/2010 09:00 PM’;
$endDtTimeVar = ’12/30/2010 09:00 AM’;
echo ‘start date:– ‘.$stDtTimeVar;
echo “<br /> <br />”;
echo ‘end date:– ‘.$endDtTimeVar;
echo “<br /> <br />”;

if(strtotime($stDtTimeVar) >= strtotime($endDtTimeVar)) {
echo ‘start date is greater.’;
}
else {
echo ‘end date is greater.’;
}

echo “<br /> <br />”;

$url = $_SERVER[‘PHP_SELF’];
$i=1;
$monthLimit=12;

$currentdate = date(“Y-m”, mktime(0,0,0,date(“m”),1,date(“Y”)));
$currentdate1 = str_replace  ( “-”  , “_”  , $currentdate);

$currentdateDisp=date(“F Y”, mktime(0,0,0,date(“m”),1,date(“Y”)));
echo “<a href=’$url?date=$currentdate1′>”.$currentdateDisp.”</a>”.”<br>”;

while($monthLimit > 0) {

$monthVal = date(“m”)-$i;

$dateDisp = date(“Y-m”, mktime(0,0,0,$monthVal,1,date(“Y”)));
$dateDisp1 = str_replace  ( “-”  , “_”  , $dateDisp);

$dateDisp2 = date(“F Y”, mktime(0,0,0,$monthVal,1,date(“Y”)));
?>
<a href='<?=$url?>?date=<?=$dateDisp1?>’><?=$dateDisp2?></a><br>
<?php
$monthLimit–;
$i=$i+1;
}
?>

Thanks,

Nilesh Prajapati

Posted by: prajapatinilesh | January 7, 2011

Marge 2 field Sybase query

TableName: ScheduledHomepage
Fields: startDate (datetime) , startHour (time)

select startDate,startHour from ScheduledHomepage
startDate                  startHour
————————– —————
NULL            NULL
May 15 2010 12:00AM         10:00AM
Mar 11 2010 12:00AM          9:00AM

//Trancate time value from full date time value.
select left(startDate,11) as startDate from ScheduledHomepage

startDate
———–
NULL
May 15 2010
Mar 11 2010

//Combine 2 field value
select left(startDate,11) +” “+ convert(varchar(8), startHour) as startDateTime from ScheduledHomepage

startDateTime
——————–

May 15 2010 10:00AM
Mar 11 2010  9:00AM

Other sample examples:

select convert(nvarchar,getdate(),101)
select convert(INT,convert(varchar,getdate(),112))
SELECT LEFT(DateTimeField, 11) FROM Table
SELECT CONVERT(VARCHAR(20), DateTimeField, 101) FROM YourTable

Thanks,

Nilesh Prajapati

Posted by: prajapatinilesh | June 10, 2010

Javascript + Array sort on Key

<HTML>
<HEAD>
<TITLE> array key sort </TITLE>
<script language=”javascript”>
jsArray = new Array();
jsArray[‘A’] = ‘Test1’;
jsArray[‘Z’] = ‘Test3’;
jsArray[‘P’] = ‘Test4’;
jsArray[‘U’] = ‘Test2’;
jsArray[‘B’] = ‘Test5’;

array = jsArray;
var keys = new Array();
for(k in array)
{
keys.push(k);
}

keys.sort( function (a, b){return (a > b) – (a < b);} );

for (var i = 0; i < keys.length; i++)
{
alert(keys[i] + ” , ” + array[keys[i]]);
}
</script>
</HEAD>

<BODY>
Javascript + Array sort on Key
</BODY>
</HTML>

SELECT REPLACE(convert(varchar(11), getdate(), 109),’ ‘,’/’)

« Newer Posts - Older Posts »

Categories