Thursday, 28 April 2011

Extract only numeric value from a string through Regular Expression

$TextVariable = 'Dummy54Da69ta';
$NumericVal = preg_replace("/[^0-9]+/","",$TextVariable);
echo $NumericVal;

Wednesday, 27 April 2011

Disable right click option

<!-- Include JQuery latest file -->

<script language="javascript" type="text/javascript">
 $(document).ready(function(){
     $(document).bind("contextmenu",function(e){
         return false;
     });
 });
</script>

Extract image from string

<?php
$contents = 'This is test content and an image tage after that. <img title="Dummy Image" src="http://www.warepin.com/wp-content/uploads/2010/03/sample-proposals-for-computer-hardware.jpg" alt="DummyImage" />
  You will get the image from the string';

$pos = stripos($contents,'<img');
$posimg = stripos($contents, ">", $pos);
$final = substr($contents, $posimg+1);
echo $final; // Total content
$len = strlen($final);

$img = substr($contents, 0, -$len);
echo $img; // The image

?>

Break a long string containing no space

$text is a long string.

$text = "45353453453erfgdvdfbfgbfgbfgb";
$newtext = wordwrap($text, 8, "\n", true);
echo $newtext;

Father of PHP

Rasmos Lerdoff