Friday, July 25, 2008

coding php to extract or get filename and extension

it's not hard to code but not easy to solve
easyiest way is use explode function but this is advance :)

 
  $url = "htpp://www.example.com/filename.txt
  $file = substr(strrchr($url, '/'), 1); //get file
  $ext = substr(strrchr($file, '.'), 1); //get extension
  $filename = substr($file,0,strrpos($file,'.')); // get file name
and another code is function to remove file in folder and/or empty folder
<?php
// ggarciaa at gmail dot com (04-July-2007 01:57)
// I needed to empty a directory, but keeping it
// so I slightly modified the contribution from
// stefano at takys dot it (28-Dec-2005 11:57)
// A short but powerfull recursive function
// that works also if the dirs contain hidden files
// $dir = the target directory
// $DeleteMe = if true delete also $dir, if false leave it alone
function SureRemoveDir($dir, $DeleteMe) {
  if(!$dh = @opendir($dir)) return;
  while (false !== ($obj = readdir($dh))) {
    if($obj=='.' || $obj=='..') continue;
    if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$obj, true);
  }
  closedir($dh);
  if($DeleteMe){
    @rmdir($dir);
  }
}
//SureRemoveDir('EmptyMe', false);
//SureRemoveDir('RemoveMe', true);
?>
link: http://th.php.net/unlink link2:

Tuesday, June 17, 2008

javascript get all link in page

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function LinkList() {
var myheader = "<head><title>Links In "+document.title+"</title></head>";
myheader = myheader + "<body>";
var myfont = "<font style="font: 8pt Verdana, Arial, Helvetica, Sans-serif; line-height:18pt;" face="verdana, tahoma, geneva" size="-1" >";
var mytext = "<center><b>Links in " + document.title + "</b><ol></center>";
var myendfont = "</font>";
var myendheader = "</body>";

windowprops = "menubars=no,location=no,toolbars=no,scrollbars=yes,"+"width=350,height=400,top=50,left=50";
self.name = "main";

if(document.all) {
for (i=0; i<document.links.length; i++) {
if(document.links[i].innerText)
if(document.links[i].innerText != " ")
mytext += "<li><a target='_new' href="+document.links[i]+">"+document.links[i].innerText+"</a><br>";
else
mytext += "<li><a target='_new' href="+document.links[i]+">"+document.links[i]+"</a><br>" ;
   }
}
else {
for (i=0; i<document.links.length; i++) {
if(document.links[i].text) {
if(((document.links[i].text).indexOf("javascript:")) == -1) {
mytext += "<li><a target='_new' href="+document.links[i]+">"+document.links[i].text+"</a><br>" ;
   }
}
else { }
   }
}
mytext = mytext + "</ol><center><a href='javascript:window.close()'>close</a></center><BR>";

linkswin = window.open("","",windowprops);
with (linkswin.document) {
open();
write(myheader + myfont + mytext + myendfont + myendheader);
close();
   }
}
//  End -->
</script>
From : The JavaScript Source!!

Sunday, June 08, 2008

prettifier javascript sourcecode syntax highlighter for blogger

easy as it does not much to configure with prettifier highlighter
1.download and see the instruction here
2. copy these code and paste befor </head>

<link href='YOUR_SITE/prettify.css' rel='stylesheet' type='text/css'/>
<script src='YOUR_SITE/prettify.js' type='text/javascript'/>
3) Wrap your code and Remember to replace < with <lt; , & with &amp;
<pre class="prettyprint">
<?php
    //comment start here
    /*and can start here*/
    #and here
    class Highlighters() {
        function result($highlighter) {
            switch ($highlighter) {
               case "chili":
               default:
                  return "FTL";
               case "syntaxhighlighter":
                  return "FTW";
            }
        }
    }
 for($i=0;$i<10;$i++){
  print_r($_POST[$i])
  return true;
  return null;
 }
    $highlighters = new Highlighters();
    printf("Chili is a nice effort, but just not for me.  Chili %s", $highlighters->result("chili"));
    printf("I am going to give SyntaxHighlighter a shot.  SyntaxHighlighter %s", $highlighters->result("syntaxhighlighter"));
?>
<HTML>
<BODY onload='init();'>
TESTING HELLO WORLD
</BODY>
</HTML>
</pre>
the css is not pretty as its name but you can modify is yourself From: http://code.google.com/p/google-code-prettify/

Saturday, June 07, 2008

javascript sourcecode syntax highlighter for blogger

I've got new things what i've find for a while HOW to user SyntaxHighlighter easy 3 step to complete this highlighter
1) Include the core files and the brushes for any language you want. Your paths may be different.

    <script type="text/javascript" src="/http/feel-free-source-code.blogspot.com/syntaxhighlighter/js/shCore.js"></script>
    <script type="text/javascript" src="/http/feel-free-source-code.blogspot.com/syntaxhighlighter/js/shBrushPhp.js"></script>
    <script type="text/javascript" src="/http/feel-free-source-code.blogspot.com/syntaxhighlighter/js/shBrushJScript.js"></script>
    <script type="text/javascript" src="/http/feel-free-source-code.blogspot.com/syntaxhighlighter/js/shBrushXml.js"></script>
2) Put this at the end of your file. If you put it before the code you want highlighted it won’t work.
<script class="javascript">
dp.SyntaxHighlighter.ClipboardSwf = "syntaxhighlighter/js/clipboard.swf";
dp.SyntaxHighlighter.HighlightAll("code");
</script>
3) Wrap your code and tell SyntaxHighlighter which brush to use. Remember to replace < with &lt; , & with &amp;
<pre name="code"  class="php">
<?php
    class Highlighters() {
        function result($highlighter) {
            switch ($highlighter) {
               case "chili":
               default:
                  return "FTL";
               case "syntaxhighlighter":
                  return "FTW";
            }
        }
    }
 for($i=0;$i<10;$i++){
  print_r($_POST[$i])
 }
    $highlighters = new Highlighters();
    printf("Chili is a nice effort, but just not for me.  Chili %s", $highlighters->result("chili"));
    printf("I am going to give SyntaxHighlighter a shot.  SyntaxHighlighter %s", $highlighters->result("syntaxhighlighter"));
?>
<HTML>
<BODY onload='init();'>
TESTING HELLO WORLD
</BODY>
</HTML>
</pre>
From : http://www.pseudocoder.com/ For blogger.com following this link