how to check xml validation recursively in folders using php

<?php
function isValidXML ( $xml ) {
	libxml_use_internal_errors( true );
	$doc = new DOMDocument('1.0', 'utf-8');
	$doc->load( $xml );
	$errors = libxml_get_errors();
	libxml_clear_errors();
    return empty( $errors );
}
function debug($content){
	$filename = 'bug.txt';
	if (!file_exists($filename)){
		touch($filename);
	}
	if (is_writable($filename)) {

		if (!$handle = fopen($filename, 'a')) {
			 echo "Cannot open file ($filename)";
			 exit;
		}

		if (fwrite($handle, $content) === FALSE) {
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);

	} else {
		echo "The file $filename is not writable \n";
		echo $content;
	}
}

function checkFolder($path)
{
	if ($handle=opendir($path))
	{
		while (false!==($file=readdir($handle)))
		{
			if ($file<>"." AND $file<>"..")
			{
				if (is_file($path.'/'.$file))
				{
					$extension = substr($file, strrpos($file, ".") + 1);
					if(strtolower($extension) == "xml"){
						if(!isValidXML($path.'/'.$file)){
							debug($path.'/'.$file."\n");
						}
					}
				}
				if (is_dir($path.'/'.$file))
				{
					checkFolder($path.'/'.$file);
				}
			}
		}
	}
}
// here write the path where you have to test xml
checkFolder(__DIR__);

?>

JQuery custom event dispatching and listening using trigger and bind

Today i create a simple application in which there are 3 text field and a submit button, submit button should be disabled until there is no text in input fields so i use JQuery’s trigger method to trigger custom event with some additional parameters( for R&D only)   and JQuery’s bind function to bind a function, which will be called when an  event triggered, We can bind more then one events to a single function

<!DOCTYPE html>
<html>
<head>
	<title>as3atoz</title>
	<script type="text/javascript" src="../day2/jquery-1.6.1.min.js"></script>
	<script>
	$("document").ready(function(){ 

		function enableSubmit()
		{
			$("#submitBtn").attr("disabled",false);
		} 

		function disableSubmit()
		{
			$("#submitBtn").attr("disabled",true); 	
		}

		$(document).bind('A_CHANGE B_CHANGE C_CHANGE', function(e,param1,param2) {
			$('#debug').html("DEBUG ::"+e.type +", "+param1+ ", "+param2);
			if($('#a_txt').val() != "" && $('#b_txt').val()  != "" && $('#c_txt').val() != ""){
				enableSubmit();
			} else {
				disableSubmit();
			}			
		});	

		$('#a_txt').keyup(function() {
			$(document).trigger('A_CHANGE',[$(this).val(),"param2"]);
		});

		$('#b_txt').keyup(function() {
			$(document).trigger('B_CHANGE', [$(this).val(),["a","b","c"]]);
		});

		$('#c_txt').keyup(function() {
			$(document).trigger('C_CHANGE', [$(this).val(),{a:"one",b:"two"}]);
		});
		disableSubmit();
	});

	</script>
</head>
<body>
	<form>		
	  <input id="a_txt"/>
	  <input id="b_txt"/>
	  <input id="c_txt"/>
	  <input id="submitBtn"  type="submit"/>
	  <div id="debug"></div>
	</form>
</body>
</html>

How to set width of DIV tag using JQuery

Setting width of div tag is very simple but i am not a html/css expert so i did some mistake by setting direct width like this

<div width="100px">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>

and it didn’t work so i google and find out some solution

Solution 1 :

<div style="width:100px">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>

 

Solution 2:

<!DOCTYPE html>
<html>
	<head>
	<title>as3atoz</title>
	<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
	<script>
		$("document").ready(function(){ 
			$("#myDiv").attr('style', 'width:200px;');
		});	
	</script>
	</head>
	<body>
		<div id="myDiv">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pretium cursus nunc id elementum. Vivamus tincidunt augue vel ipsum congue pulvinar eget nec elit. Aliqua</div>
	</body>
</html>

 

 

Say Hello to JQuery

JQuery is a JavaScript library,

Lets start a basic program this will show a alert message when screen load

<!DOCTYPE html>

<html>
<head>
	<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
	<script>
	$("document").ready(function(){ alert("Hello JQuery") })	
	</script>
</head>
<body>
</body>
</html>
$("document").ready() work same as window.onload( alert("Hello JQuery") )
You can download JQuery from http://docs.jquery.com/Downloading_jQuery

how to show html password field as text on mouseover

this code will show password field’s text when you rollover your mouse and when you roll out again you will see password field

<!DOCTYPE html>
<html>
	<head>
	<title>as3atoz</title>
		<script>
		// called when mouse over
		function mouseOverListenerFunc(o){
			o.type = "text";
		}
		// called when mouse out
		function mouseOutListenerFunc(o){
			o.type = "password";
		}
		</script>
	</head>
	<body>
		<input type="password" onmouseover="mouseOverListenerFunc(this)" onmouseout="mouseOutListenerFunc(this)" />
	</body>
</html>