Function fixMyEffingText(strText) strText = Replace(strText,"Source","Dest") ' Smart Open Single Quote strText = Replace(strText,Chr(145),"'") ' Smart Close Single Quote strText = Replace(strText,Chr(146),"'") ' Smart Open Double Quote strText = Replace(strText,Chr(147),Chr(34)) ' Smart Close Double Quote strText = Replace(strText,Chr(148),Chr(34)) ' Smart Short Hyphen strText = Replace(strText,Chr(150),"-") ' Smart Long Hyphen strText = Replace(strText,Chr(151),"--") ' Odd Apostrophe Top-Right strText = Replace(strText,Chr(180),"'") ' Cidilla without a letter / Odd Comma strText = Replace(strText,Chr(184),",") ' Bullet strText = Replace(strText,Chr(149),"·") ' Smart Dot dot dot strText = Replace(strText,Chr(133),"...") ' Bottom Quote strText = Replace(strText,Chr(132),Chr(34)) ' Approx symbol at top strText = Replace(strText,Chr(152),"~") ' Approx symbol (long) strText = Replace(strText,Chr(126),"~") ' Line Feed strText = Replace(strText,Chr(10),"<br>") ' CR strText = Replace(strText,Chr(21),"<br>") ' Do all Greater than Char 128 For i = 129 to 255 c = "&#" & i & ";" strText = Replace(strText,Chr(i),c) Next fixMyEffingText = strText End Function
Tag Archive for function
Strip nasty Microsoft tags
Element Collection Manipulation Shortcut Using MooTools 1.2
// MooTools Looping Example (Bad/Long)
$$('.toggler').each(function(el) {
el.addEvent('mouseenter',function(e) {
el.fireEvent('click');
});
});
// MooTools Collection Example (Good/Short)
$$('.toggler').addEvent('mouseenter', function() { this.fireEvent('click'); });
Oman3D – Simple gotoAndStop button function
function functionName (e:MouseEvent):void{
gotoAndStop("lableName");
}
instanceName.addEventListener(MouseEvent.CLICK, functionName);
Random password
<?php
/**
* Random Password Generator
* @public
* @param int $length Length of password to generate
* @return string Returns randomised password
*/
function randomPword($length)
{
$seed = 'ABC123DEF456GHI789JKL0MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$seedLength = strlen($seed);
$random = '';
for ($i=1; $i <= $length; $i++)
{
$charPos = mt_rand(0, ($seedLength - 1));
$singleChar = substr($seed, $charPos, 1);
$random .= $singleChar;
}
return $random;
}
?>
Create a grid of bottons
private function generateBoard(startX:Number,startY:Number,totalRows:Number,totalCols:Number,buttonSize:Number):void {
buttons = new Array();
var colCounter:uint;
var rowCounter:uint;
for(rowCounter = 0; rowCounter < totalRows; rowCounter++) {
for(colCounter = 0; colCounter < totalCols; colCounter++) {
var b:Button = new Button();
b.x = startX + (colCounter*buttonSize);
b.y = startY + (rowCounter*buttonSize);
b.addEventListener(MouseEvent.CLICK, letterClicked);
b.label = getRandomLetter().toUpperCase();
b.setSize(buttonSize,buttonSize);
b.name = "buttonRow"+rowCounter+"Col"+colCounter;
addChild(b);
buttons.push(b);
}
}
}
AS3 Random Range
private function randRange(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
Getting Full URL/Path with ASP
function GetPath()
query_string = request.ServerVariables("QUERY_STRING")
if query_string <> "" then
query_string = "?" & query_string
end if
GetPath = "http://" & request.ServerVariables("SERVER_NAME") & request.ServerVariables("URL") & query_string
end function
Limited Text Function – PHP
A function to limit text
Of course you can also copy this code and use it freely in the scripts that you may write.
php:
<?php
function limit_text( $text, $limit )
{
// figure out the total length of the string
if( strlen($text)>$limit )
{
# cut the text
$text = substr( $text,0,$limit );
# lose any incomplete word at the end
$text = substr( $text,0,-(strlen(strrchr($text,' '))) );
}
// return the processed string
return $text;
}
?>
How do I use this function?
Now to use it, you'll just have to paste the function above, into your script or onto a 'includes' file (containing all your functions) if you prefer.
Let's assume you want to paste it with your script - so, this is what you could do:
php:
<?php
// Filename: test.php
// ==================
// Our sample text
$long = 'Offers a discussion board, news portal, '
.'web-related articles, tutorials, scripts,'
.' tech blog, photo gallery, oekaki drawing,'
.' fun games, and more.';
// we only want the text to be 15 characters long.
$short15 = limit_text( $long,15 );
// perhaps we need one with just 6 characters.
$short06 = limit_text( $long,6 );
// we output some text
echo "<p>$long</p>
";
echo "<p>$short15</p>
";
echo "<p>$short06</p>
";
// ============================================
// now we paste our LIMIT_TEXT() function below
// ============================================
function limit_text( $text, $limit )
{
if( strlen($text)>$limit )
{
$text = substr( $text,0,$limit );
$text = substr( $text,0,-(strlen(strrchr($text,' '))) );
}
return $text;
}
?>
simple Body ID Function
<?php
function setBodyId() {
$path = $_SERVER['REQUEST_URI'];
if(!isset($bodyId)) {
if(eregi(’^/about/’,$path) == 1) {
$bodyId = ‘about’;
} else if(eregi(’^/blog/’,$path) == 1) {
$bodyId = ‘blog’;
} else if(eregi(’^/contact/’,$path) == 1) {
$bodyId = ‘contact’;
} else if(eregi(’^/work/’,$path) == 1) {
$bodyId = ‘work’;
} else if(eregi(’^/play/’,$path) == 1) {
$bodyId = ‘play’;
} else if ($path == â€) {
$bodyId = ‘home’;
} else {
$bodyId = ‘general’;
}
}
return $bodyId;
}
$bodyID=setBodyId();
?>
<body id="<?=$bodyID?>">