tag:blogger.com,1999:blog-77058585430897500082015-08-09T23:28:46.577-07:00Custom functions i used to use[PHP, JAVASCRIPT, JQUERY]I have been using PHP, Javascript, Jquery with codeignitor for the past 2 years. I used to use and make many custom functions for development purpose of which some are noteworthy and may be useful for others also.
I would like to share and discuss such custom functions with all PHP developers and freshersMohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-7705858543089750008.post-72821129582363057912015-08-09T23:28:00.003-07:002015-08-09T23:28:46.591-07:00Removing Files you have added files to Git that you want it to track no longer<div dir="ltr" style="text-align: left;" trbidi="on">Removing Files you have added files to Git that you want it to track no longer.<br /><br />Scenario: You added a file to Git accidentally or you may want to remove a file from current push<br /><b>You cannot run git rm </b>because you want to keep a copy of the file(git rm command will delete the file from file system)<br /><b><br /></b><br /><b> Solution: </b>To tell Git to stop tracking a file, but still keep it on your local system, run the following command<br /><br /><div class="scriptbox">git rm --cached [file_name] </div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0tag:blogger.com,1999:blog-7705858543089750008.post-79735056340392536112014-12-23T02:35:00.002-08:002014-12-23T03:33:52.042-08:00Handle images uploaded using multi file select using PHP in serverside<div dir="ltr" style="text-align: left;" trbidi="on"><br /><div class="titlebox">Multi file upload via ajax can be implemented using jQuery. You can find the detailed documentation <a href="http://customphpfunctions.blogspot.in/2014/12/multi-file-select-preview-without.html" target="_blank">here.</a></div>OR copy & paste the following link to address bar of your browser <br /><div class="scriptbox"><a href="http://customphpfunctions.blogspot.in/2014/12/multi-file-select-preview-without.html" target="_blank">http://customphpfunctions.blogspot.in/2014/12/multi-file-select-preview-without.html</a></div><br /><div class="scriptbox"><?php<br />/**<br /> * Function to save images uploaded from content tab using bulk upload<br /> *<br /> * @return multitype:array<br /> */<br />public function save_uploaded_files()<br />{<br /> $response = array('status' => 0, 'message' => '');<br /> $posted_data = $_POST;<br /> $user_name = $posted_data['username'];<br /> $config['allowed_types'] = array('gif','jpg', 'jpeg', 'jpe', 'png');<br /> $config['upload_path'] = getcwd().'/uploadpath/';<br /><br /> $values = array();<br /> $originalFileName = '';<br /> try {<br /> $fileDetails = $this->process_uploaded_file($originalFileName, $values, $user_id);<br /> } catch (Exception $e) {<br /> $response['message'] = 'Something went wrong. Please try again later';<br /><br /> return $response;<br /> }<br /> $response['status'] = 1;<br /> $response['message'] = 'Files saved';<br /> foreach ($fileDetails as $details) {<br /> $response['file_info'][] = array(<br /> 'original' => $details['uploaded_file_name'],<br /> 'target' => $details['target_name'],<br /> );<br /> }<br /><br /> return $response;<br />}<br /><br />/**<br /> * Function to move uploaded file to target location<br /> *<br /> * @param string $fileName<br /> * @param array $values pass by reference<br /> *<br /> * @return string file name<br /> */<br />public function process_uploaded_file()<br />{ <br /> $bulk_upload = $_POST['bulk_upload'];<br /> $config['upload_path'] = getcwd().'/uploaded/';<br /> $config['allowed_types'] = array('gif','jpg', 'jpeg', 'jpe', 'png');<br /> $uploaded_file_info = false;<br /> $number_of_images = get_number_of_images_uploaded($_FILES['image_uploader_multiple']);<br /> if ($number_of_images > 0) {<br /> foreach ($_FILES['image_uploader_multiple']['name'] as $key => $uploaded_file_name) {<br /> $uploaded_path_parts = pathinfo($uploaded_file_name);<br /> $temp_name = $_FILES['image_uploader_multiple']['tmp_name'][$key];<br /> $fileName = uniqid('', true).".".date("YmdHis").".".sprintf("%06d",rand());<br /> $fileFullName = $fileName.".".$uploaded_path_parts['extension'];<br /> $target_path_parts = pathinfo($fileName);<br /> $target_file_name = $target_path_parts['filename'].'.'.$uploaded_path_parts['extension'];<br /><br /> $i = 1;<br /> while (file_exists($config['upload_path'].$target_file_name)) {<br /> $target_file_name = $target_path_parts['filename'].'-'.($i++).'.'.$uploaded_path_parts['extension'];<br /> }<br /> <br /> $config['file_name'] = $target_file_name;<br /> move_uploaded_file($temp_name, $config['upload_path'].$target_file_name);<br /> chmod_apply($config['upload_path'].$target_file_name);<br /><br /> $uploaded_file_info[] = array(<br /> 'target_name' => $target_file_name,<br /> 'uploaded_file_name' => $uploaded_file_name<br /> );<br /> }<br /> }<br /><br /> return $uploaded_file_info;<br />}<br /><br />/**<br /> * Function to get number of images uploaded<br /> *<br /> * @param array $image_uploader_multiple<br /> *<br /> * @return number<br /> */<br />function get_number_of_images_uploaded($image_uploader_multiple)<br />{<br /> $count = 0;<br /> if (isset($image_uploader_multiple['error']) && is_array($image_uploader_multiple['error'])) {<br /> foreach($image_uploader_multiple['error'] as $error) {<br /> if ($error != 4) {<br /> $count++;<br /> }<br /> }<br /> }<br /><br /> return $count;<br />}<br /><br />/**<br /> * Function to apply proper permission to the upload file<br /> *<br /> * @param $filename<br /> * @return bool<br /> */<br />function chmod_apply($filename = '') {<br /> $stat = @ stat(dirname($filename));<br /> $perms = $stat['mode'] & 0007777;<br /> $perms = $perms & 0000666;<br /> if ( @chmod($filename, $perms) )<br /> return true;<br /> return false;<br />}</div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0Thiruvananthapuram, Kerala, India8.5241391 76.936637600000048.5241391 76.93663760000004 8.5241391 76.93663760000004tag:blogger.com,1999:blog-7705858543089750008.post-59604222896432226992014-12-23T01:19:00.001-08:002014-12-29T03:31:53.086-08:00Multi file select preview without uploading and delayed upload<div dir="ltr" style="text-align: left;" trbidi="on"><ul style="text-align: left;"><li>Ajax file upload</li><li>Multi file select</li><li>Selective upload of files in multi select </li></ul><br /><br />Requirement: Implement a file selector with multiple file select with following functions.<br />1. Allow user to select images only.<br />1. Preview of all selected images should be populated on the page without uploading the image to the server on selecting images.<br />2. User should be able to filter images to be actually uploaded to the server from the previews, User should be able to remove selected files using a close button.<br />3. On clicking upload button, the images listed in the preview should be uploaded to server without page re-load(Ajax).<br /><br />Implementation plan: <br />1. User can select images using multiple <a href="https://developer.mozilla.org/en-US/docs/Web/API/FileList" target="_blank">File Input</a>. <br />2. Preview of images selected can be populated by using a <a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader" target="_blank">FileReader</a> object and can be appended to html preview area.<br />3. Index of selected images can be used to generate class name of the respective image container, sothat we can match images selected and the one which is previewed.<br />4. Using a button populated near preview, we can close the preview(Remove the element from the html dom - make sure the container with matching class name is also removed)<br />5. On clicking the upload button, we can iterate through the images selected in the file selector and search for the corresponding image preview container having matching class name to find if the preview of the image is not removed by the user, if present, add them to <a href="https://developer.mozilla.org/en-US/docs/Web/API/FormData" target="_blank">formData</a> object and submit them via ajax to the server.<br /><br />Screen shots:<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-jrPtj7yk3gs/VJj-8Y4YMrI/AAAAAAAAIEk/ep08YIYv1ow/s1600/Screenshot-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-jrPtj7yk3gs/VJj-8Y4YMrI/AAAAAAAAIEk/ep08YIYv1ow/s1600/Screenshot-1.png" height="67" width="400" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-f8KQ3ZZHPS0/VJj-8fKkRbI/AAAAAAAAIEs/tAtY-5OY-60/s1600/Screenshot-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-f8KQ3ZZHPS0/VJj-8fKkRbI/AAAAAAAAIEs/tAtY-5OY-60/s1600/Screenshot-2.png" height="220" width="400" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-ttdWERj4MUE/VJj-8XJFQGI/AAAAAAAAIEo/LII0MCvEa9U/s1600/Screenshot-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-ttdWERj4MUE/VJj-8XJFQGI/AAAAAAAAIEo/LII0MCvEa9U/s1600/Screenshot-3.png" height="171" width="400" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-gt0fYb9hVQk/VJj-9DmRfxI/AAAAAAAAIE4/xdF1SG2LjYk/s1600/Screenshot-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-gt0fYb9hVQk/VJj-9DmRfxI/AAAAAAAAIE4/xdF1SG2LjYk/s1600/Screenshot-4.png" height="286" width="400" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-JVE79aLG9mg/VJj-9UrrrOI/AAAAAAAAIFA/RAv89G3ryMc/s1600/Screenshot-5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-JVE79aLG9mg/VJj-9UrrrOI/AAAAAAAAIFA/RAv89G3ryMc/s1600/Screenshot-5.png" height="263" width="400" /></a></div><br /><br />Code on github: <a href="https://github.com/imaimai86/multi-file-select-preview-without-uploading-and-delayed-upload">https://github.com/imaimai86/multi-file-select-preview-without-uploading-and-delayed-upload</a><br /><br />Demo on jsFiddle: <a href="http://jsfiddle.net/anas/6v8Kz/7/embedded/result/">http://jsfiddle.net/anas/6v8Kz/7/embedded/result/</a><br /><br /><a href="http://jsfiddle.net/anas/6v8Kz/7/">http://jsfiddle.net/anas/6v8Kz/7/</a> <br /><br />Code Hint:<br /><br /><div class="demobox"><b>HTML:</b></div><div class="htmlbox"><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><p><br /><label for="image_uploader_multiple">Image:</label><br /></p><br /><form><br /><table width="70%" id="multi_file_uploader"><br /> <tbody><br /> <tr class="imageSelectorContainer"><br /> <td valign="top"><br /> <input type="file" name="image_uploader_multiple[]" </span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> value="" class="multipleImageFileInput" </span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span>style="width:50%" </span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> onchange="show_image_preview(this);" </span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span>accept="image/*" multiple=""></span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> <!-- Preview container table --><br /> <table class="imagePreviewTable"></table><br /> </td><br /> <td valign="top" align="right"><br /> <input type="button" value="X" title="Remove" </span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span>class="removeButton" style="display:none;" </span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span>onclick="remove_file_uploader(this)"><br /> </td><br /> <td valign="top"></span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> <input type="button" value="+" title="Add" </span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span>class="addButton" style="" </span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span>onclick="add_new_file_uploader(this)"> </span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </td><br /> </tr><br /> </tbody><br /> <tbody><br /> <tr><br /> <td colspan="3" class="buttonBox"><br /> <input type="submit" value="Save Images"><br /> </td><br /> </tr><br /> </tbody><br /></table><br /></form><br /><div class="overlay"><br /> <div class="overlay_content">Saving....<br /></span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> <img src="spinner.gif" /></span></i></span><br /><span style="font-size: large;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </div><br /></div></span></i></span></div><br /><div class="demobox"><b>CSS:</b></div><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;"><style type="text/css"><br />.buttonBox{<br /> padding: 20px;<br /> text-align: center;<br />}<br />.imagePreviewTable{<br /> border: 1px solid #000;<br /> display: none;<br />}<br />.overlay {<br /> position:absolute; top:0; left:0; right:0; bottom:0; background-color:rgba(0, 0, 0, 0.85); background: url(data:;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAABl0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuNUmK/OAAAAATSURBVBhXY2RgYNgHxGAAYuwDAA78AjwwRoQYAAAAAElFTkSuQmCC) repeat scroll transparent\9; /* ie fallback png background image */ z-index:9999; color:white; text-align:center; height:5000px; display:none;<br />}<br />.overlay_content{<br /> padding:300px;<br />}<br /></style></span></i><b> </b></div><br /><div class="demobox"><b>JAVASCRIPT:</b></div>Include jquery <br /><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;"><script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> </span></i></div><br /><div class="scriptbox"><span class="hint-span">Open "Script" tag</span><br /><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;"><script type="text/javascript"> </span></i></div><br /><span class="hint-span">Bind form submission with function to upload images using jQuery</span><br /><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;">$(document).ready(function(){<br /> $('form').submit(function(ev){<br /> $('.overlay').show();<br /> $(window).scrollTop(0);<br /> return upload_images_selected(ev, ev.target);<br /> })<br />})<br /></span></i></div><br /><span class="hint-span">Function to display preview of images selected using the input selector. </span><br /><span class="hint-span">Logic: For each images selected, add a preview row to the image preview table, with a class name corresponding to the index of the file in the file selector(</span><span class="hint-span"><i><span style="font-family: Georgia,"Times New Roman",serif;">imagePreviewRow_<index_of_image_in_file_selector></span></i>). Iterate through the files selected using the file selector input and check the mime type of the selected file, if it is an image, create a file reader object to read the content of the file and append file content to the preview row.</span><br /><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;">function show_image_preview(file_selector) {<br /> <span class="code-hint-inline">//files selected using current file selector</span><br /> var files = file_selector.files;<br /> <span class="code-hint-inline">//Container of image previews</span> <br /> var imageContainer = $(file_selector).next('table.imagePreviewTable');<br /> <span class="code-hint-inline">//Number of images selected</span> <br /> var number_of_images = files.length;<br /> <span class="code-hint-inline">//Build image preview row</span> <br /> var imagePreviewRow = $( '<tr class="imagePreviewRow_0">'+</span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"> '<td valign=top style="width: 510px;"></td>' +</span></i><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i>'<td valign=top><input type="button" '+ </span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i>'</span></i>'value="X" </span></i><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;">title="Remove Image"</span></i>'+ </span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i>' class="removeImageButton" '+</span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i>'imageIndex="0" '+</span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span></i>' onclick="remove_selected_image(this)" />'+</span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i>'</td></tr> ');<br /> <span class="code-hint-inline">//Add image preview row</span> <br /> $(imageContainer).html(imagePreviewRow);<br /> if (number_of_images > 1) {<br /> for (var i =1; i<number_of_images; i++) {<br /> <span class="code-hint-inline"> /**<br /> * Generate class name of the respective image container appending index </span></span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><span class="code-hint-inline"><i><span style="font-family: Georgia,"Times New Roman",serif;"><span class="code-hint-inline"> * </span></span></i>of selected images, sothat we can match images selected and </span></span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><span class="code-hint-inline"><i><span style="font-family: Georgia,"Times New Roman",serif;"><span class="code-hint-inline"> * </span></span></i>the one <i><span style="font-family: Georgia,"Times New Roman",serif;"><span class="code-hint-inline"></span></span></i>which is previewed<br /> */ </span> <br /> var newImagePreviewRow = $(imagePreviewRow)</span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span></i>.clone()</span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span></i></span></i>.</span></i></span></i>removeClass('imagePreviewRow_0')</span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i></span></i></span></i></span></i></span></i>.addClass('imagePreviewRow_'+i);<br /> $(newImagePreviewRow).find('input[type="button"]').attr('imageIndex', i);<br /> $(imageContainer).append(newImagePreviewRow);<br /> }<br /> }<br /> for (var i = 0; i < files.length; i++) {<br /> var file = files[i];<br /> <span class="code-hint-inline"> /**<br /> * Allow only images<br /> */</span> <br /> var imageType = /image.*/;<br /> if (!file.type.match(imageType)) {<br /> continue;<br /> }<br /> <br /> <span class="code-hint-inline"> /**<br /> * Create an image dom object dynamically<br /> */</span> <br /> var img = document.createElement("img");<br /> <br /> <span class="code-hint-inline"> /**<br /> * Get preview area of the image<br /> */</span> <br /> var preview = $(imageContainer).find('tr.imagePreviewRow_'+i).find('td:first');<br /><br /> <span class="code-hint-inline"> /**<br /> * Append preview of selected image to the corresponding container<br /> */</span> <br /> preview.append(img); <br /> <br /> <span class="code-hint-inline"> /**<br /> * Set style of appended preview(Can be done via css also)<br /> */</span> <br /> preview.find('img').addClass('previewImage')</span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i>.css({'max-width': '500px', 'max-height': '500px'});<br /> <br /> <span class="code-hint-inline"> /**<br /> * Initialize file reader<br /> */</span> <br /> var reader = new FileReader();<br /> <span class="code-hint-inline"> /**<br /> * Onload event of file reader assign target image to the preview<br /> */</span> <br /> reader.onload = (function(aImg) { return function(e) { </span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"> aImg.src = e.target.result; }; </span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i>})(img);<br /> <span class="code-hint-inline"> /**<br /> * Initiate read<br /> */</span> <br /> reader.readAsDataURL(file);<br /> }<br /> <span class="code-hint-inline"> /**<br /> * Show preview<br /> */</span> <br /> $(imageContainer).show();<br />}<br /></span></i></div><br /><span class="hint-span">Function to remove selected image from preview. This function removes the image from DOM instead of hiding them. </span><br /><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;">function remove_selected_image(close_button)<br />{<br /> <span class="code-hint-inline"> /**<br /> * Remove this image from preview<br /> */</span> <br /> var imageIndex = $(close_button).attr('imageindex');<br /> $(close_button).parents('.imagePreviewRow_' + imageIndex).remove();<br />}<br /></span></i></div><br /><span class="hint-span">Function to upload remaining images available in the preview list.</span><br /><span class="hint-span">Logic: Iterate through each file input and each files selected, and check if the image is in the preview. this checking can be done easily by checking the image preview row with name(</span><span class="hint-span"><span class="hint-span"><i><span style="font-family: Georgia,"Times New Roman",serif;">imagePreviewRow_<index_of_image_in_file_selector></span></i></span>) corresponding to the index of the file in the file selector input exists. If the preview is available, create a </span><span class="hint-span"><i><span style="font-family: Georgia,"Times New Roman",serif;">formData</span></i> object and append the image to the object. Now post the form data object using "</span><span class="hint-span"><i><span style="font-family: Georgia,"Times New Roman",serif;">XMLHttpRequest" </span></i>to the server(Ajax).</span><br /><span class="hint-span">This function sends an ajax request corresponding to each file selector to tackle the maximum file upload size limit that can be uploaded to the server. This method avoids uploading large number of files simultaneously to the server there by getting caught by the max file upload limit.</span><br /><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;">function upload_images_selected(event, formObj)<br />{<br /> event.preventDefault();<br /> <span class="code-hint-inline">//Get number of images</span> <br /> var imageCount = $('.previewImage').length;<br /> <span class="code-hint-inline">//Get all multi select inputs</span> <br /> var fileInputs = document.querySelectorAll('.multipleImageFileInput');<br /> <span class="code-hint-inline">//Url where the image is to be uploaded</span> <br /> var url= "/admin/content/upload";<br /> <span class="code-hint-inline">//Get number of inputs</span> <br /> var number_of_inputs = $(fileInputs).length; <br /> var inputCount = 0;<br /><br /> <span class="code-hint-inline">//Iterate through each file selector input</span> <br /> $(fileInputs).each(function(index, input){<br /> <br /> fileList = input.files;<br /> <span class="code-hint-inline">// Create a new FormData object.</span> <br /> var formData = new FormData();<br /> <span class="code-hint-inline">//Extra parameters can be added to the form data object</span> <br /> formData.append('bulk_upload', '1');<br /> formData.append('username', $('input[name="username"]').val());<br /> <span class="code-hint-inline">//Iterate throug each images selected by each file selector and </span></span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><span class="code-hint-inline"><i><span style="font-family: Georgia,"Times New Roman",serif;"> <span class="code-hint-inline">//</span></span></i>find if the image is present in the preview</span> <br /> for (var i = 0; i < fileList.length; i++) {<br /> if($(input).next('.imagePreviewTable').find('.imagePreviewRow_'+i).length!=0){<br /> var file = fileList[i];<br /> <span class="code-hint-inline">// Check the file type.</span> <br /> if (!file.type.match('image.*')) {<br /> continue;<br /> }<br /> <span class="code-hint-inline">// Add the file to the request.</span> <br /> formData.append('image_uploader_multiple[' +(inputCount++)+ ']', </span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"> file, </span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i>file.name);<br /> }<br /> }<br /> <span class="code-hint-inline">// Set up the request.</span> <br /> var xhr = new XMLHttpRequest();<br /> xhr.open('POST', url, true);<br /> xhr.onload = function () {<br /> if (xhr.status === 200) {<br /> var jsonResponse = JSON.parse(xhr.responseText);<br /> if (jsonResponse.status == 1) {<br /> $(jsonResponse.file_info).each(function(){<br /> <span class="code-hint-inline">//Iterate through response and find data corresponding </span></span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><span class="code-hint-inline"><i><span style="font-family: Georgia,"Times New Roman",serif;"> <span class="code-hint-inline">//</span></span></i>to each file uploaded</span> <br /> var uploaded_file_name = this.original;<br /> var saved_file_name = this.target;<br /> var file_name_input = '<input type="hidden" class="image_name"</span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"> name="image_names[]" </span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i>value="' +saved_file_name+ '" />';<br /> file_info_container.append(file_name_input);<br /> <br /> imageCount--;<br /> })<br /> <span class="code-hint-inline">//Decrement count of inputs to find all images </span></span></i><br /><i><span style="font-family: Georgia,"Times New Roman",serif;"><span class="code-hint-inline"><i><span style="font-family: Georgia,"Times New Roman",serif;"> <span class="code-hint-inline">//</span></span></i>selected by all multi select are uploaded</span> <br /> number_of_inputs--;<br /> if(number_of_inputs == 0) {<br /> <span class="code-hint-inline">//All images selected by each file selector is uploaded</span> <br /> <span class="code-hint-inline">//Do necessary acteion post upload</span> <br /> $('.overlay').hide();<br /> }<br /> } else {<br /> if (typeof jsonResponse.error_field_name != 'undefined') {<br /> <span class="code-hint-inline">//Do appropriate error action</span> <br /> } else {<br /> alert(jsonResponse.message);<br /> }<br /> $('.overlay').hide();<br /> event.preventDefault();<br /> return false;<br /> }<br /> } else {<br /> alert('Something went wrong!');<br /> $('.overlay').hide();<br /> event.preventDefault();<br /> }<br /> };<br /> xhr.send(formData);<br /> })<br /> <br /> return false;<br />}</span></i></div><br /><br /><span class="hint-span">Function to populate new file uploader on clicking the "+" button near to existing file selectors. On clicking the "+" button, the row containing the "+" button is cloned, selected files and previews if any are removed and appended to the end of the container. </span><br /><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;">function add_new_file_uploader(addBtn) {<br /> var currentRow = $(addBtn).parent().parent();<br /> var newRow = $(currentRow).clone();<br /> $(newRow).find('.previewImage, .imagePreviewTable').hide();<br /> $(newRow).find('.removeButton').show();<br /> $(newRow).find('table.imagePreviewTable').find('tr').remove();<br /> $(newRow).find('input.multipleImageFileInput').val('');<br /> $(addBtn).parent().parent().parent().append(newRow);<br />}<br /></span></i></div><br /><span class="hint-span">File selector along with selected images are removed. </span><br /><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;">function remove_file_uploader(removeBtn) {<br /> $(removeBtn).parent().parent().remove();<br />}<br /></span></i></div><br /><span class="hint-span">Close "Script" tag</span><br /><div class="scriptbox"><i><span style="font-family: Georgia,"Times New Roman",serif;"></script> </span></i></div><br /></div><div class="titlebox">Serverside PHP code to handle uploads can be found <a href="http://customphpfunctions.blogspot.in/2014/12/handle-images-uploaded-using-multi-file.html">here</a></div>OR copy & paste the following link to address bar of your browser <br /><div class="scriptbox"><a href="http://customphpfunctions.blogspot.in/2014/12/handle-images-uploaded-using-multi-file.html" target="_blank">http://customphpfunctions.blogspot.in/2014/12/handle-images-uploaded-using-multi-file.html</a></div><br /><div class="titlebox">Customize file select input <a href="http://customphpfunctions.blogspot.in/2013/11/custom-look-for-file-selector.html">here</a></div>OR copy & paste the following link to address bar of your browser <br /><div class="scriptbox"><a href="http://customphpfunctions.blogspot.in/2013/11/custom-look-for-file-selector.html" target="_blank">http://customphpfunctions.blogspot.in/2013/11/custom-look-for-file-selector.html</a></div><br /><div class="scriptbox"><h2>References:</h2><ul style="text-align: left;"><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader" target="_blank">MDN: FileReader Documentation</a> </li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/FormData" target="_blank">MDN: FormData Documentation</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest" target="_blank">MDN: XMLHttpRequest Documentation</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/FileList" target="_blank">MDN: FileList Documentation</a></li><li><a href="http://www.w3.org/TR/XMLHttpRequest/" target="_blank">W3C: XMLHttpRequest Specification</a></li></ul></div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0Thiruvananthapuram, Kerala, India8.5582754050835987 76.8809509277343758.5425734050836 76.860780927734382 8.573977405083598 76.901120927734368tag:blogger.com,1999:blog-7705858543089750008.post-81248099994356528612013-11-06T21:47:00.001-08:002014-12-23T03:26:52.818-08:00Custom look for file selector <div dir="ltr" style="text-align: left;" trbidi="on"><div class="titlebox">Custom look for file selector </div><br />Here is a way of adding custom styled buttons for file selctor inputs. <b><i>Working</i>:</b>Overlay a transparent "<input type="file" />" over a styled button or other element<br /><br /><b>Code:</b> <br /><div class="scriptbox"> <div id="" style="height: 30px; overflow: hidden; position: absolute; width: 300px; word-break: keep-all;"><br /> <input style="width: 100px;" type="button" value="select" /><br /> <span id="files"><br /> No files selected. <br /> </span><br /> </div><br /> <input id="selector" style="height: 30px; opacity: 0; position: absolute; width: 100px;" type="file" /><br /> </div><br /><br /></div><b>Try this on jsFiddle:</b> <a href="http://jsfiddle.net/bMb59/">http://jsfiddle.net/bMb59/</a></div> <div class="titlebox">Multi file select with ajax upload: <a href="http://customphpfunctions.blogspot.in/2014/12/multi-file-select-preview-without.html">here</a></div>OR copy & paste the following link to address bar of your browser <br /><div class="scriptbox">http://customphpfunctions.blogspot.in/2014/12/handle-images-uploaded-using-multi-file.html </div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0Thiruvananthapuram, Kerala, India8.4874949 76.9486238.2362274 76.6258995 8.7387623999999988 77.271346499999993tag:blogger.com,1999:blog-7705858543089750008.post-45210535774297732522012-06-29T10:05:00.000-07:002012-06-29T10:06:18.930-07:00MySql Backup Class<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on"><br /><br /><div class="titlebox">MySql Backup Class written by Vagharshak Tozalakyan <vagh@armdex.com></div><br />This class is written in a file mysql_backup.class.php<br />This file is to be included in the file where we actually call this class to be executed.<br /><br /><b><br /></b><br /><br /><div><div style="font-weight: bold;">HOW TO USE</div><div style="font-weight: bold;"><i><span style="color: #444444; font-family: 'Courier New', Courier, monospace;"><br /></span></i></div><span style="color: #444444;"><i></i></span><br /><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>HOW TO USE</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b><br /></b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>1. Create the instance of MySQL_Backup class.</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>2. Define necessary properties.</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>3. Call Execute() method to create backup.</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b><br /></b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>require_once 'mysql_backup.class.php';</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj = new MySQL_Backup();</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj->server = 'localhost';</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj->username = 'username';</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj->password = 'password';</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj->database = 'dbname';</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj->tables = array();</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj->drop_tables = true;</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj->struct_only = false;</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj->comments = true;</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>$backup_obj->fname_format = 'd_m_y__H_i_s';</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>if (!$backup_obj->Execute(MSB_DOWNLOAD, '', true))</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>{</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b> die($backup_obj->error);</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b>}</b></i></span></div><div style="font-family: 'Courier New', Courier, monospace;"><span style="color: #444444;"><i><b><br /></b></i></span></div><br /><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-weight: bold;"><span style="color: #444444;"><i><span style="font-family: Georgia, 'Times New Roman', serif;">PUBLIC PROPERTIES</span></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $server = 'localhost';</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>The name of MySQL server.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $port = 3306;</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>The port of MySQl server.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $username = 'root';</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Database username.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $password = '';</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Database password.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $database = '';</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Name of the database.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $link_id = -1;</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>MySQL link identifier of the current connection. You can set this if you</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>want to connect the MySQL server by your own.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $connected = false;</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Set true if the connection is already established before calling Execute().</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $tables = array();</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Tables you want to backup. All tables in the database will be backed up if</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>this array is empty.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $drop_tables = true;</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Add DROP TABLE IF EXISTS queries before CREATE TABLE in backup file.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $struct_only = false;</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Only structure of the tables will be backed up if true.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $comments = true;</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Include comments in backup file if true.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $backup_dir = '';</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Directory on the server where the backup file will be placed. Used only if task</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>parameter equals to MSB_SAVE in Execute() method.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $fname_format = 'd_m_y__H_i_s';</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Default file name format.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>var $error = '';</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>Error message.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><span style="color: #444444;"><i><b><span style="font-family: Georgia, 'Times New Roman', serif;">PUBLIC METHODS</span></b></i></span><br /><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>function Execute($task = MSB_STRING, $fname = '', $compress = false)</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>$task - operation to perform: MSB_STRING - return SQL commands as a string;</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i> MSB_SAVE - create the backup file on the server; MSB_DOWNLOAD - save backup</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i> file in the user's computer.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>$fname - optional name of backup file.</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i>$compress - use GZip compression?</i></span></div><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div><br /><div style="font-family: 'Courier New', Courier, monospace; font-weight: bold;"><span style="color: #444444;"><i><br /></i></span></div></div><br /><b><span style="font-family: 'Courier New', Courier, monospace;">mysql_backup.class.php</span></b></div><div class="scriptbox"><?php<br /><br />/*<br /> MySQL database backup class, version 1.0.0<br /> Written by Vagharshak Tozalakyan <vagh@armdex.com><br /> Released under GNU Public license<br />*/<br /><br /><br />define('MSB_VERSION', '1.0.0');<br /><br />define('MSB_NL', "\r\n");<br /><br />define('MSB_STRING', 0);<br />define('MSB_DOWNLOAD', 1);<br />define('MSB_SAVE', 2);<br /><br />class MySQL_Backup<br />{<br /><br /> var $server = 'localhost';<br /> var $port = 3306;<br /> var $username = 'root';<br /> var $password = '';<br /> var $database = '';<br /> var $link_id = -1;<br /> var $connected = false;<br /> var $tables = array();<br /> var $drop_tables = true;<br /> var $struct_only = false;<br /> var $comments = true;<br /> var $backup_dir = '';<br /> var $fname_format = 'd_m_y__H_i_s';<br /> var $error = '';<br /><br /><br /> function Execute($task = MSB_STRING, $fname = '', $compress = false)<br /> {<br /> if (!($sql = $this->_Retrieve()))<br /> {<br /> return false;<br /> }<br /> if ($task == MSB_SAVE)<br /> {<br /> if (empty($fname))<br /> {<br /> $fname = $this->backup_dir;<br /> $fname .= date($this->fname_format);<br /> $fname .= ($compress ? '.sql.gz' : '.sql');<br /> }<br /> return $this->_SaveToFile($fname, $sql, $compress);<br /> }<br /> elseif ($task == MSB_DOWNLOAD)<br /> {<br /> if (empty($fname))<br /> {<br /> $fname = date($this->fname_format);<br /> $fname .= ($compress ? '.sql.gz' : '.sql');<br /> }<br /> return $this->_DownloadFile($fname, $sql, $compress);<br /> }<br /> else<br /> {<br /> return $sql;<br /> }<br /> }<br /><br /><br /> function _Connect()<br /> {<br /> $value = false;<br /> if (!$this->connected)<br /> {<br /> $host = $this->server . ':' . $this->port;<br /> $this->link_id = mysql_connect($host, $this->username, $this->password);<br /> }<br /> if ($this->link_id)<br /> {<br /> if (empty($this->database))<br /> {<br /> $value = true;<br /> }<br /> elseif ($this->link_id !== -1)<br /> {<br /> $value = mysql_select_db($this->database, $this->link_id);<br /> }<br /> else<br /> {<br /> $value = mysql_select_db($this->database);<br /> }<br /> }<br /> if (!$value)<br /> {<br /> $this->error = mysql_error();<br /> }<br /> return $value;<br /> }<br /><br /><br /> function _Query($sql)<br /> {<br /> if ($this->link_id !== -1)<br /> {<br /> $result = mysql_query($sql, $this->link_id);<br /> }<br /> else<br /> {<br /> $result = mysql_query($sql);<br /> }<br /> if (!$result)<br /> {<br /> $this->error = mysql_error();<br /> }<br /> return $result;<br /> }<br /><br /><br /> function _GetTables()<br /> {<br /> $value = array();<br /> if (!($result = $this->_Query('SHOW TABLES')))<br /> {<br /> return false;<br /> }<br /> while ($row = mysql_fetch_row($result))<br /> {<br /> if (empty($this->tables) || in_array($row[0], $this->tables))<br /> {<br /> $value[] = $row[0];<br /> }<br /> }<br /> if (!sizeof($value))<br /> {<br /> $this->error = 'No tables found in database.';<br /> return false;<br /> }<br /> return $value;<br /> }<br /><br /><br /> function _DumpTable($table)<br /> {<br /> $value = '';<br /> $this->_Query('LOCK TABLES ' . $table . ' WRITE');<br /> if ($this->comments)<br /> {<br /> $value .= '#' . MSB_NL;<br /> $value .= '# Table structure for table `' . $table . '`' . MSB_NL;<br /> $value .= '#' . MSB_NL . MSB_NL;<br /> }<br /> if ($this->drop_tables)<br /> {<br /> $value .= 'DROP TABLE IF EXISTS `' . $table . '`;' . MSB_NL;<br /> }<br /> if (!($result = $this->_Query('SHOW CREATE TABLE ' . $table)))<br /> {<br /> return false;<br /> }<br /> $row = mysql_fetch_assoc($result);<br /> $value .= str_replace("\n", MSB_NL, $row['Create Table']) . ';';<br /> $value .= MSB_NL . MSB_NL;<br /> if (!$this->struct_only)<br /> {<br /> if ($this->comments)<br /> {<br /> $value .= '#' . MSB_NL;<br /> $value .= '# Dumping data for table `' . $table . '`' . MSB_NL;<br /> $value .= '#' . MSB_NL . MSB_NL;<br /> }<br /> $value .= $this->_GetInserts($table);<br /> }<br /> $value .= MSB_NL . MSB_NL;<br /> $this->_Query('UNLOCK TABLES');<br /> return $value;<br /> }<br /><br /><br /> function _GetInserts($table)<br /> {<br /> $value = '';<br /> if (!($result = $this->_Query('SELECT * FROM ' . $table)))<br /> {<br /> return false;<br /> }<br /> while ($row = mysql_fetch_row($result))<br /> {<br /> $values = '';<br /> foreach ($row as $data)<br /> {<br /> $values .= '\'' . addslashes($data) . '\', ';<br /> }<br /> $values = substr($values, 0, -2);<br /> $value .= 'INSERT INTO ' . $table . ' VALUES (' . $values . ');' . MSB_NL;<br /> }<br /> return $value;<br /> }<br /><br /><br /> function _Retrieve()<br /> {<br /> $value = '';<br /> if (!$this->_Connect())<br /> {<br /> return false;<br /> }<br /> if ($this->comments)<br /> {<br /> $value .= '#' . MSB_NL;<br /> $value .= '# MySQL database dump' . MSB_NL;<br /> $value .= '# Created by MySQL_Backup class, ver. ' . MSB_VERSION . MSB_NL;<br /> $value .= '#' . MSB_NL;<br /> $value .= '# Host: ' . $this->server . MSB_NL;<br /> $value .= '# Generated: ' . date('M j, Y') . ' at ' . date('H:i') . MSB_NL;<br /> $value .= '# MySQL version: ' . mysql_get_server_info() . MSB_NL;<br /> $value .= '# PHP version: ' . phpversion() . MSB_NL;<br /> if (!empty($this->database))<br /> {<br /> $value .= '#' . MSB_NL;<br /> $value .= '# Database: `' . $this->database . '`' . MSB_NL;<br /> }<br /> $value .= '#' . MSB_NL . MSB_NL . MSB_NL;<br /> }<br /> if (!($tables = $this->_GetTables()))<br /> {<br /> return false;<br /> }<br /> foreach ($tables as $table)<br /> {<br /> if (!($table_dump = $this->_DumpTable($table)))<br /> {<br /> $this->error = mysql_error();<br /> return false;<br /> }<br /> $value .= $table_dump;<br /> }<br /> return $value;<br /> }<br /><br /><br /> function _SaveToFile($fname, $sql, $compress)<br /> {<br /> if ($compress)<br /> {<br /> if (!($zf = gzopen($fname, 'w9')))<br /> {<br /> $this->error = 'Can\'t create the output file.';<br /> return false;<br /> }<br /> gzwrite($zf, $sql);<br /> gzclose($zf);<br /> }<br /> else<br /> {<br /> if (!($f = fopen($fname, 'w')))<br /> {<br /> $this->error = 'Can\'t create the output file.';<br /> return false;<br /> }<br /> fwrite($f, $sql);<br /> fclose($f);<br /> }<br /> return true;<br /> }<br /><br /><br /> function _DownloadFile($fname, $sql, $compress)<br /> {<br /> header('Content-disposition: filename=' . $fname);<br /> header('Content-type: application/octetstream');<br /> header('Pragma: no-cache');<br /> header('Expires: 0');<br /> echo ($compress ? gzencode($sql) : $sql);<br /> return true;<br /> }<br /><br />}<br /><br />?></div><br /><br /><br /><br /><b><span style="font-family: 'Courier New', Courier, monospace;">execute_db_backup.php</span></b><br /><br /><div class="scriptbox"><?<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>/*<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>|-----------------------<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>|Example MySQL Backup File <span style="white-space: pre;"> </span> <span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>| <br /><span class="Apple-tab-span" style="white-space: pre;"> </span>|Written by: Justin Keller <kobenews@cox.net> <br /><span class="Apple-tab-span" style="white-space: pre;"> </span>|Released under GNU Public license.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>|<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>|Only use with MySQL database backup class,<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>|version 1.0.0 written by Vagharshak Tozalakyan<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>|<vagh@armdex.com>.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>|-----------------------<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>*/<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>require_once 'mysql_backup.class.php';<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj = new MySQL_Backup();<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//--- EDIT - REQUIRED SETUP VARIABLES ------->><br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->server = 'localhost';<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->port = 3306;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->username = '';<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->password = '';<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->database = '';<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//Tables you wish to backup. All tables in the database will be backed up if this array is null.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->tables = array();<br /><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//--- END - REQUIRED SETUP VARIABLES ------->><br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//---OPTIONAL PREFERENCE VARIABLES ------->><br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//Add DROP TABLE IF EXISTS queries before CREATE TABLE in backup file.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->drop_tables = true;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//Only structure of the tables will be backed up if true.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->struct_only = false;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//Include comments in backup file if true.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->comments = true;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//Directory on the server where the backup file will be placed. Used only if task parameter equals MSB_SAVE.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->backup_dir = '/';<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//Default file name format.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$backup_obj->fname_format = 'm_d_Y';<br /><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//---END - OPTIONAL PREFERENCE VARIABLES ------->><br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//---EDIT - REQUIRED EXECUTE VARIABLES ------->><br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>/*<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>Task:<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>MSB_STRING - Return SQL commands as a single output string.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>MSB_SAVE - Create the backup file on the server.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>MSB_DOWNLOAD - Download backup file to the user's computer.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>*/<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$task = MSB_DOWNLOAD;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//Optional name of backup file if using 'MSB_SAVE' or 'MSB_DOWNLOAD'. If nothing is passed, the default file name format will be used.<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$filename = '';<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//Use GZip compression if using 'MSB_SAVE' or 'MSB_DOWNLOAD'?<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$use_gzip = true;<br /><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//---END - REQUIRED EXECUTE VARIABLES ------->><br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>//---NO NEED TO ANYTHING BELOW THIS LINE ------->><br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span class="Apple-tab-span" style="white-space: pre;"> </span>if (!$backup_obj->Execute($task, $filename, $use_gzip))<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>{<br /><span class="Apple-tab-span" style="white-space: pre;"> </span> $output = $backup_obj->error;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>}<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>else<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>{<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$output = 'Operation Completed Successfully At: <b>' . date('g:i:s A') . '</b><i> ( Local Server Time )</i>';<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />?><br /><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html xmlns="http://www.w3.org/1999/xhtml"><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><br /><title>MySQL Backup</title><br /></head><br /><body><br /><?<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>echo $output;<br />?><br /></body><br /></html> </div><br /></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0Karunagappally, Kerala, India9.054716 76.5353789.039035 76.515637 9.0703970000000016 76.555118999999991tag:blogger.com,1999:blog-7705858543089750008.post-339070008322770302012-02-04T10:55:00.000-08:002012-02-04T11:31:52.461-08:00Looping through XML with jQuery<div dir="ltr" style="text-align: left;" trbidi="on">Handling Xml on web pages is used to be a headache when i started coding ajax events. Most of the times we will be knowing the tag name of particular data we need and we can use<br /><div class="scriptbox">xml.find('result').find('userTypeDetails') </div><br /> But this is not always the case with xml.<br />I have a scenario in which i get an xml like the one follows as ajax response.<br /><div class="scriptbox"><br /><result><br /> <permissionDetails><br /> <addBusiness>0</addBusiness><br /> <viewBusiness>1</viewBusiness><br /> <viewBusinessChargeDetails>1</viewBusinessChargeDetails><br /> <editBusinessProfile>0</editBusinessProfile><br /> <editBusinessAccount>1</editBusinessAccount><br /> <editBusinessGatewayInfo>1</editBusinessGatewayInfo><br /> <deleteBusiness>1</deleteBusiness><br /> <addBillingUser>0</addBillingUser><br /> <viewBillingUser>0</viewBillingUser><br /> <viewBillingUserChargeDetails>0</viewBillingUserChargeDetails><br /> <editBillingUserProfile>1</editBillingUserProfile><br /> <editBillingUserAccount>1</editBillingUserAccount><br /> <deleteBillingUser>1</deleteBillingUser><br /> <viewCharge>0</viewCharge><br /> <editCharge>1</editCharge><br /> <viewRegularReport>0</viewRegularReport><br /> <addRegularReport>0</addRegularReport><br /> <editRegularReport>0</editRegularReport><br /> <deleteRegularReport>0</deleteRegularReport><br /> <viewAdvancedReport>1</viewAdvancedReport><br /> <addAdvancedReport>0</addAdvancedReport><br /> <editAdvancedReport>1</editAdvancedReport><br /> <deleteAdvancedReport>1</deleteAdvancedReport><br /> <viewUser>0</viewUser><br /> <addUser>0</addUser><span class="Apple-tab-span" style="white-space: pre;"> </span><br /> <editUser>1</editUser><span class="Apple-tab-span" style="white-space: pre;"> </span><br /> <deleteUser>1</deleteUser><span class="Apple-tab-span" style="white-space: pre;"> </span><br /> <viewTemplate>0</viewTemplate><span class="Apple-tab-span" style="white-space: pre;"> </span><br /> <addTemplate>0</addTemplate><span class="Apple-tab-span" style="white-space: pre;"> </span><br /> <editTemplate>0</editTemplate><span class="Apple-tab-span" style="white-space: pre;"> </span><br /> <deleteTemplate>1</deleteTemplate><br /> <viewMail>1</viewMail><span class="Apple-tab-span" style="white-space: pre;"> </span><br /> <sendMail>1</sendMail><br /> <deleteMail>0</deleteMail><br /> <profileDetailsView>1</profileDetailsView><br /> <profileDetailsEdit>1</profileDetailsEdit><br /> <viewAccount>0</viewAccount><br /> <editAccount>1</editAccount><br /> <deleteAccount>1</deleteAccount><br /> <viewGatewayInfo>1</viewGatewayInfo><br /> <editGatewayInfo>1</editGatewayInfo><br /> <deleteGatewayInfo>0</deleteGatewayInfo><br /> </permissionDetails><span class="Apple-tab-span" style="white-space: pre;"> </span><br /></result></div><br />Now i have to update an html page as in figure<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-bNv7tZbEDPw/Ty2CMlBhcsI/AAAAAAAAFGs/vjP6l6Nt7yA/s1600/form+1.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="237" src="http://4.bp.blogspot.com/-bNv7tZbEDPw/Ty2CMlBhcsI/AAAAAAAAFGs/vjP6l6Nt7yA/s320/form+1.gif" width="320" /></a></div><br />One of the solution is to create checkboxes with name same as tagname in xml and iterate through the xml to check or uncheck the check box with name same as the current tag name depending upon value. <br />dd<br /><div class="scriptbox"><br />xml.find('result').find('permissionDetails').each(function(){<br /> $(this).children().each(function(){<br /> var tagName=this.tagName;<br /> var val=$(this).text();<br /> if(val==1){<br /> $('input:checkbox[name='+tagName+']').attr('checked',true);<br /> }<br /> else if(val==0){<br /> $('input:checkbox[name='+tagName+']').removeAttr('checked');<br /> }<br /> })<br />});<br /></div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0tag:blogger.com,1999:blog-7705858543089750008.post-88065945864735981682012-02-03T22:48:00.001-08:002012-02-04T10:51:06.997-08:00code ignitor: Getting the error “Disallowed Key Characters”<div dir="ltr" style="text-align: left;" trbidi="on"><br /><div class="titlebox">Code Ignitor: Getting the error “Disallowed Key Characters” ? </div><br /> <b>I</b>n <b>C</b>odeignitor, its usual for the developer getting the Error: "Disallowed Key Characters"<br /> This error used to drove newbies nuts. I am not sure about the reason and the fix provided by codeignitor help page not works some times[Most of the times from my experience]. It is also difficult to find what caused the error.<br /><br />Here is solution that help in diagnosis of the problem.<br /><br />In the core CI code in system/libraries is a file called input.php This small modification would show the actual data that caused the Problem.<br /><br />Around line number 199<br /><div><br /></div><br /><div class="scriptbox">function _clean_input_keys($str)<br />{<br />if ( ! preg_match(“/^[a-z0-9:_\/-]+$/i”, $str))<br />{<br />exit(‘Disallowed Key Characters: ‘.$str); <br />// The variable $str was added to display the data in question.<br />}<br />return $str;<br />}</div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0Karunagappally, Kerala, India9.054716 76.5353789.039035 76.515637 9.0703970000000016 76.555118999999991tag:blogger.com,1999:blog-7705858543089750008.post-38430158753704050382012-02-03T13:35:00.000-08:002012-02-04T10:52:13.573-08:00jQuery: exclude $(this) from selector<div dir="ltr" style="text-align: left;" trbidi="on"><br /><div dir="ltr" style="text-align: left;" trbidi="on">I have a set of text boxes and i want to check for duplication of set values in any of the text box. ie, no text box should contain a value that is entered in any other.<br /><br /><div class="htmlbox"><b><u><span style="font-size: small;">HTML </span></u></b><br /><div><form method="post" action="" onsubmit="return validate()"><br /> <table><br /> <tr><br /> <td> <br /> <input type="textkbox" name="priority[]" /><br /> </td> <br /> <tr> <br /><br /> <tr><br /> <td><br /> <input type="textkbox" name="priority[]" /><br /> </td><br /> <tr><br /><br /> <tr><br /> <td><br /> <input type="textkbox" name="priority[]" /><br /> </td><br /> <tr><br /><br /> <tr><br /> <td><br /> <input type="textkbox" name="priority[]" /><br /> </td><br /> <tr><br /><br /> <tr><br /> <td><br /> <input type="textkbox" name="priority[]" /><br /> </td><br /> <tr><br /> </table><br /></form> </div></div><div class="demobox">DEMO <br /><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script>var firstError=''; function validate(){ $('input[type="text"]').each(function(){ var mastrPriority=$(this); $('input[type="text"]').not(this).each(function(){ var priority=$(this); if(mastrPriority.val()==priority.val()){ seterrormessage(mastrPriority,'Duplicate Priority Values.'); seterrormessage(priority,'Duplicate Priority Values.'); if(firstError==''){ alert("Priority Field should contain unique values."); firstError=mastrPriority; } } }); }) if(firstError!=''){ firstError.focus(); return false; } else{ $("#formOfpage").hide(); return false; } } function seterrormessage(field,msg){ var errorBox=$(field).parent().find('div.validationError').first(); if(errorBox.length>0){ errorBox.text(msg); } else{ $(field).after('</br><div class="validationError"> '+msg+'</a>'); } } </script><br /><form action="" id="formOfpage" method="post" onsubmit="return validate()"><table> <tbody><tr> <td><input name="priority[]" type="text" /></td> </tr><tr> <td><input name="priority[]" type="text" /></td> </tr><tr> <td><input name="priority[]" type="text" /></td> </tr><tr> <td><input name="priority[]" type="text" /></td> </tr><tr> <td><input name="priority[]" type="text" /></td> </tr><tr> <td><input type="submit" value="SUBMIT" /></td> </tr></tbody></table></form></div><div class="scriptbox"><u><b>JAVASCRIPT</b></u><br /><u><b><br /></b></u><br />var firstError=''; <br />function validate(){<br /> $('input[type="text"]').each(function(){<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>var mastrPriority=$(this);<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>$('input[type="text"]').not(this).each(function(){<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>var priority=$(this);<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span style="white-space: pre;"> </span>if(mastrPriority.val()==priority.val()){<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>seterrormessage(mastrPriority,'Duplicate Priority Values.');<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>seterrormessage(priority,'Duplicate Priority Values.');<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>if(firstError==''){<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span style="white-space: pre;"> </span>alert("Priority Field should contain unique values.");<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span style="white-space: pre;"> </span>firstError=mastrPriority;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>}<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span style="white-space: pre;"> </span>}<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>});<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><span style="white-space: pre;"> </span>})<br /><span style="white-space: pre;"> </span>if(firstError!=''){<br /><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>firstError.focus();<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;<br /><span style="white-space: pre;"> </span>}<br /><span style="white-space: pre;"> </span>else{<br /><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return true;<br /><span style="white-space: pre;"> </span>}<br />}<br /><br /><br />function seterrormessage(field,msg){<br /><span style="white-space: pre;"> </span>var errorBox=$(field).parent().find('div.validationError').first();<br /><span style="white-space: pre;"> </span>if(errorBox.length>0){<br /><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>errorBox.text(msg);<br /><span style="white-space: pre;"> </span>}<br /><span style="white-space: pre;"> </span>else{<br /><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>$(field).after('</br><div class="validationError">'+msg+'</a>');<br /><span style="white-space: pre;"> </span>}<br />}</div>The function <span style="font-family: 'Courier New', Courier, monospace; font-size: 14px;"><b><u>validate()</u></b></span> iterates through each text box and compare values of each box with all others except current one. The current text box is excluded from the set of text boxes using <b style="font-family: 'Courier New', Courier, monospace; font-size: 14px;"><u>.not(this)</u></b>.<br /><br /></div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0Karunagappally, Kerala, India9.054716 76.5353789.039035 76.515637 9.0703970000000016 76.555118999999991tag:blogger.com,1999:blog-7705858543089750008.post-65695749942685109992012-01-04T12:20:00.000-08:002012-02-03T21:43:40.679-08:00Find your user's their IP address:<div dir="ltr" style="text-align: left;" trbidi="on"><br /><div class="titlebox">Show your user's their IP address: </div><br />Retrieving the user's IP address is actually much simpler than you might think, and can be done in a single line. Getenv("REMOTE_ADDR") will return the IP address of the person visiting your site. Generally this is accurate, however if the user is running through a proxie server, then it will return the address of the proxie.<br />In this example, we retrieve the user's IP and then simply echo it's value back to the user.<br /><div class="scriptbox"><?php<br /> //Gets the IP address<br /> $ip = getenv("REMOTE_ADDR") ;<br /> Echo "Your IP is " . $ip;<br /> ?> </div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0Karunagappally, Kerala, India9.054716 76.5353789.039035 76.515637 9.0703970000000016 76.555118999999991tag:blogger.com,1999:blog-7705858543089750008.post-6430813131463497812011-12-05T11:41:00.001-08:002011-12-05T11:44:56.070-08:00How do I count the number of tr elements within a table using jquery.<div dir="ltr" style="text-align: left;" trbidi="on"><br /><div class="MsoNormal"><span class="apple-style-span"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; font-family: Arial, sans-serif; font-size: 10.5pt; line-height: 115%;">This can be a most basic question, but it may keep us busy us for hours wasting our time.</span></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal" style="line-height: 13.5pt; margin-bottom: 12.0pt; vertical-align: baseline;"><span style="font-family: Arial, sans-serif; font-size: 10.5pt;">Use a selector that will select all the rows and take the length.<o:p></o:p></span></div><div class="MsoNormal" style="background: #EEEEEE; line-height: 13.5pt; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; vertical-align: baseline;"><span style="border: none windowtext 1.0pt; color: darkblue; font-family: Consolas; font-size: 10.5pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: "Times New Roman"; padding: 0in;">var</span><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; font-family: Consolas; font-size: 10.5pt; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in;"> rowCount = $(</span><span style="border: none windowtext 1.0pt; color: maroon; font-family: Consolas; font-size: 10.5pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: "Times New Roman"; padding: 0in;">'#myTable tr'</span><span style="border-bottom-color: windowtext; border-bottom-style: none; border-bottom-width: 1pt; border-left-color: windowtext; border-left-style: none; border-left-width: 1pt; border-right-color: windowtext; border-right-style: none; border-right-width: 1pt; border-top-color: windowtext; border-top-style: none; border-top-width: 1pt; font-family: Consolas; font-size: 10.5pt; padding-bottom: 0in; padding-left: 0in; padding-right: 0in; padding-top: 0in;">).length;<br /><!--[if !supportLineBreakNewLine]--><br /><!--[endif]--></span><span style="font-family: Consolas; font-size: 10.5pt;"><o:p></o:p></span></div><div class="MsoNormal" style="line-height: 13.5pt; margin-bottom: 12.0pt; vertical-align: baseline;"><span style="font-family: Arial, sans-serif; font-size: 10.5pt;">Note: this approach also counts all trs of every nested table!<o:p></o:p></span></div><div class="MsoNormal"><span style="border: none windowtext 1.0pt; font-family: "Times New Roman","serif"; font-size: 10.0pt; line-height: 115%; mso-border-alt: none windowtext 0in; mso-fareast-font-family: "Times New Roman"; padding: 0in;">$('#myTable tr').size() will return the same value<o:p></o:p></span></div><div class="MsoNormal"><span style="border: none windowtext 1.0pt; font-family: "Times New Roman","serif"; font-size: 10.0pt; line-height: 115%; mso-border-alt: none windowtext 0in; mso-fareast-font-family: "Times New Roman"; padding: 0in;">the docs indicate that length is preferred over size() because it's faster</span></div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0tag:blogger.com,1999:blog-7705858543089750008.post-87925991431413684392011-12-04T11:24:00.001-08:002013-04-23T21:29:33.049-07:00Javascript IsInteger<div dir="ltr" style="text-align: left;" trbidi="on"><br />A simple and javascript function to check whether the string is an integer.<br /><br />function isInteger(s){<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>var i;<br /> for (i = 0; i < s.length; i++){<br /> // Check that current character is number.<br /> var c = s.charAt(i);<br /> if (((c < "0") || (c > "9"))){<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;<br /><span class="Apple-tab-span" style="white-space: pre;"> </span>}<br /> }<br /> // All characters are numbers.<br /> return true;<br />}</div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0Karunagappally, Kerala, India9.054716 76.5353789.039035 76.515637 9.0703970000000016 76.555118999999991tag:blogger.com,1999:blog-7705858543089750008.post-50286374910035056672011-12-03T05:54:00.001-08:002011-12-04T11:26:03.386-08:00How to change PHP's eregi to preg_match<div dir="ltr" style="text-align: left;" trbidi="on"><br /><h1 style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: 'Trebuchet MS', 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 23px; line-height: 1.3; margin-bottom: 7px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /></h1><div><br /></div><div><span class="Apple-style-span" style="background-color: #ffeeee; color: #660000; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px;">This function <b>eregi</b> has been </span><em class="emphasis" style="background-color: #ffeeee; color: #660000; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; font-weight: bold; text-align: justify;">DEPRECATED</em><span class="Apple-style-span" style="background-color: #ffeeee; color: #660000; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: justify;"> as of <b>PHP 5.3.0. </b>Relying on this feature is highly discouraged.</span></div><div><span class="Apple-style-span" style="background-color: #ffeeee; color: #660000; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: justify;"><br /></span></div><div><span class="Apple-style-span" style="background-color: white; text-align: justify;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: large;">Now what we need is to replace the eregi functions used in our old applications with some new functions that are still not depreciated...</span></span></div><div style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: large;">First i will describe functionality of eregi() and then i will go for appropriate function to replace it.</span></div><div style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: large;"><br /></span></div><div style="text-align: justify;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: large;"><b>eregi():</b></span></div><div style="text-align: justify;"><span class="refname" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;">eregi</span><span class="Apple-style-span" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px;"> — </span><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;">Case insensitive regular expression match</span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;">Syntax:</span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><br /></span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><span class="type">int</span> <span class="methodname"><b>eregi</b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-style: italic;">$pattern</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-style: italic;">$string</tt></span> [, <span class="methodparam"><span class="type">array</span> <tt class="parameter reference" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-style: italic;">&$regs</tt></span> ] )</span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><br /></span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;">This function is identical to <span class="function"><a class="function" href="http://www.php.net/manual/en/function.ereg.php" style="border-bottom-color: rgb(0, 0, 153); border-bottom-style: solid; border-bottom-width: 1px; color: #000099; text-decoration: none;">ereg()</a></span> except that it ignores case distinction when matching alphabetic characters.</span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><br /></span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"></span><br /><div style="font-family: 'Times New Roman'; font-size: medium; text-align: left;"><h3 class="title" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: #000066; font-family: verdana, arial, helvetica, sans-serif; font-size: 15px; margin-top: 0px; padding-top: 0px; text-align: -webkit-auto;"> <span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;">Parameters</span></h3></div><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"></span><br /><div style="font-family: 'Times New Roman'; font-size: medium; text-align: left;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><br /></span><br /><br /><br /><br /><dt style="font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><span class="term" style="border-bottom-color: rgb(221, 221, 221); border-bottom-style: groove; border-bottom-width: 1px; font-size: 1.2em;"><i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">pattern</tt></i></span></span></dt><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><dd style="background-color: #eeeeff; border-bottom-color: rgb(255, 255, 255); border-bottom-style: groove; border-bottom-width: 2px; border-left-color: rgb(255, 255, 255); border-left-style: groove; border-left-width: 2px; border-right-color: rgb(255, 255, 255); border-right-style: groove; border-right-width: 2px; border-top-color: rgb(255, 255, 255); border-top-style: groove; border-top-width: 2px; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; margin-bottom: 0.5em; margin-left: 2em; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0.5em; padding-left: 0.5em; padding-right: 0.5em; padding-top: 0.5em; text-align: -webkit-auto;"><div class="para">Case insensitive regular expression.</div></dd><dt style="font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><span class="term" style="border-bottom-color: rgb(221, 221, 221); border-bottom-style: groove; border-bottom-width: 1px; font-size: 1.2em;"><i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">string</tt></i></span></dt><dd style="background-color: #eeeeff; border-bottom-color: rgb(255, 255, 255); border-bottom-style: groove; border-bottom-width: 2px; border-left-color: rgb(255, 255, 255); border-left-style: groove; border-left-width: 2px; border-right-color: rgb(255, 255, 255); border-right-style: groove; border-right-width: 2px; border-top-color: rgb(255, 255, 255); border-top-style: groove; border-top-width: 2px; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; margin-bottom: 0.5em; margin-left: 2em; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0.5em; padding-left: 0.5em; padding-right: 0.5em; padding-top: 0.5em; text-align: -webkit-auto;"><div class="para">The input string.</div></dd><dt style="font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><span class="term" style="border-bottom-color: rgb(221, 221, 221); border-bottom-style: groove; border-bottom-width: 1px; font-size: 1.2em;"><i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">regs</tt></i></span></dt><dd style="background-color: #eeeeff; border-bottom-color: rgb(255, 255, 255); border-bottom-style: groove; border-bottom-width: 2px; border-left-color: rgb(255, 255, 255); border-left-style: groove; border-left-width: 2px; border-right-color: rgb(255, 255, 255); border-right-style: groove; border-right-width: 2px; border-top-color: rgb(255, 255, 255); border-top-style: groove; border-top-width: 2px; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; margin-bottom: 0.5em; margin-left: 2em; margin-right: 0px; margin-top: 0.5em; padding-bottom: 0.5em; padding-left: 0.5em; padding-right: 0.5em; padding-top: 0.5em; text-align: -webkit-auto;"><div class="para">If matches are found for parenthesized substrings of <i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">pattern</tt></i> and the function is called with the third argument <i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">regs</tt></i>, the matches will be stored in the elements of the array <i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">regs</tt></i>.</div><div class="para">$regs[1] will contain the substring which starts at the first left parenthesis; $regs[2] will contain the substring starting at the second, and so on. $regs[0] will contain a copy of the complete string matched.</div></dd></span></div><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"></span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><br /></span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; text-align: -webkit-auto;"></span><br /><div class="refsect1 returnvalues" id="refsect1-function.eregi-returnvalues" style="border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 2px; border-collapse: collapse; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 2px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 2px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 2px; font-size: 14px; margin-bottom: 1em; margin-left: 1em; margin-right: 1em; margin-top: 1em; padding-bottom: 1em; padding-left: 1em; padding-right: 1em; padding-top: 1em;"><h3 class="title" style="background-color: transparent; border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: #000066; font-size: 15px; margin-top: 0px; padding-top: 0px;"> <span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; text-align: -webkit-auto;">return Values</span></h3><div class="para"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; text-align: -webkit-auto;">Returns the length of the matched string if a match for <i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">pattern</tt></i> was found in <i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">string</tt></i>, or <b><tt style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">FALSE</tt></b> if no matches were found or an error occurred.</span></div><div class="para"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; text-align: -webkit-auto;">If the optional parameter <i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">regs</tt></i> was not passed or the length of the matched string is 0, this function returns 1.</span></div></div><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; text-align: -webkit-auto;"></span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><br /></span></div><div style="text-align: justify;"><span class="dc-title" style="background-color: white; text-align: -webkit-auto;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: large;">A good alternative is to use </span></span><span class="Apple-style-span" style="background-color: white; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; white-space: pre;">preg_match()</span><span class="Apple-style-span" style="background-color: white; font-family: 'Courier New', Courier, monospace; font-size: large;"> function</span></div><div style="text-align: justify;"><span class="Apple-style-span" style="background-color: white; font-family: 'Courier New', Courier, monospace; font-size: large;"><br /></span></div><div style="text-align: justify;"><span class="Apple-style-span" style="background-color: white; font-family: 'Courier New', Courier, monospace; font-size: large;">Now lets talk about </span><span class="refname" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;">preg_match</span></div><div style="text-align: justify;"><span class="refname" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><br /></span></div><div style="text-align: justify;"><span class="refname" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; text-align: -webkit-auto;"><span class="refname">preg_match</span> — <span class="dc-title">Perform a regular expression match</span></span></div><div style="text-align: justify;"><span class="refname" style="text-align: -webkit-auto;"><span class="dc-title"></span></span><br /><h3 class="title" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: #000066; font-family: verdana, arial, helvetica, sans-serif; font-size: 15px; margin-top: 0px; padding-top: 0px;"> <span class="refname" style="text-align: -webkit-auto;"><span class="dc-title"><span class="Apple-style-span" style="background-color: white;">Description</span></span></span></h3><span class="refname" style="text-align: -webkit-auto;"><span class="dc-title"></span></span><br /><div class="methodsynopsis dc-description" style="background-color: #eeeeff; border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; border-left-color: black; border-left-style: solid; border-left-width: 1px; border-right-color: black; border-right-style: solid; border-right-width: 1px; border-top-color: black; border-top-style: solid; border-top-width: 1px; font-family: verdana, arial, helvetica, sans-serif; font-size: 14px; padding-bottom: 0.5em; padding-left: 0.5em; padding-right: 0.5em; padding-top: 0.5em;"><span class="refname" style="text-align: -webkit-auto;"><span class="dc-title"><span class="type">int</span> <span class="methodname"><b>preg_match</b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-style: italic;">$pattern</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-style: italic;">$subject</tt></span> [, <span class="methodparam"><span class="type">array</span> <tt class="parameter reference" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-style: italic;">&$matches</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-style: italic;">$flags</tt><span class="initializer" style="font-style: italic;"> = 0</span></span> [, <span class="methodparam"><span class="type">int</span><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-style: italic;">$offset</tt><span class="initializer" style="font-style: italic;"> = 0</span></span> ]]] )</span></span></div><span class="refname" style="text-align: -webkit-auto;"><span class="dc-title"></span></span><br /><div class="para rdfs-comment" style="font-family: verdana, arial, helvetica, sans-serif; font-size: 14px;"><span class="refname" style="text-align: -webkit-auto;"><span class="dc-title"><span class="Apple-style-span" style="background-color: white;">Searches <i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">subject</tt></i> for a match to the regular expression given in <i><tt class="parameter" style="font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace;">pattern</tt></i>.</span></span></span></div><span class="refname" style="text-align: -webkit-auto;"><span class="dc-title"></span></span><br /><div class="para rdfs-comment" style="font-family: verdana, arial, helvetica, sans-serif; font-size: 14px;"><span class="refname" style="text-align: -webkit-auto;"><span class="dc-title"><span class="Apple-style-span" style="background-color: white;"><br /></span></span></span></div><span class="refname" style="text-align: -webkit-auto;"><span class="dc-title"><div class="para rdfs-comment"></div><h3 class="title" style="background-color: transparent; border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: #000066; font-family: verdana, arial, helvetica, sans-serif; font-size: 15px; margin-top: 0px; padding-top: 0px;"> More details can be found at <a href="http://in2.php.net/manual/en/function.preg-match.php">php.net</a> <a href="http://in2.php.net/manual/en/function.preg-match.php" style="font-family: 'Times New Roman'; font-size: medium; font-weight: normal; text-align: justify;">http://in2.php.net/manual/en/function.preg-match.php</a></h3><div>Now How to replace eregi with preg_match</div><div><br /></div><div><table style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 13px; line-height: 12px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; vertical-align: baseline;"><tbody style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><tr style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><td class="votecell" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top; width: 60px;"><div class="vote" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: center; vertical-align: baseline;"><span class="vote-count-post" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #808185; display: block; font-size: 31px; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /></span></div></td><td class="answercell" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><div class="post-text" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-size: 14px; line-height: 18px; margin-bottom: 5px; margin-left: 0px; margin-right: 5px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; width: 660px;"><div style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: both; margin-bottom: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">You will need to change three things</div><ol style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; list-style-image: initial; list-style-position: initial; margin-bottom: 1em; margin-left: 30px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">need to add pattern delimiters (can be any character, but most commonly a forward slash)</li><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">[[:alnum:]] will need to be replaced with the PCRE equivalent</li><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">The "i" in "eregi" means case-insensitive, which PCRE does with a flag, specifically the <code style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">i</code> flag.</li></ol><div style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: both; margin-bottom: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">Otherwise, the rest looks PCRE compatible (yes, that's kind of redundant =P)</div><pre class="lang-php prettyprint" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><code style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="str" style="background-attachment: initial; background-clip: initial; background-color: #b4a7d6; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">"/^[a-z0-9][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i"</span></code></pre></div></td></tr></tbody></table></div><div><br /></div><div><br /></div></span></span></div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0tag:blogger.com,1999:blog-7705858543089750008.post-8194915722049157512011-12-01T09:36:00.001-08:002011-12-04T11:26:18.646-08:00How to change version of php in Xampp<div dir="ltr" style="text-align: left;" trbidi="on"><br />Take this example that makes PHP version from 5.3 to 5.2 in Xampp<br /><br /><br /><ol style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; list-style-image: initial; list-style-position: initial; margin-bottom: 1em; margin-left: 30px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">Download and install latest xampp to G:\xampp. As of 2010/03/12, this is 1.7.3.</li><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">Download the zip of xampp-win32-1.7.0.zip, which is the latest xampp distro without php 5.3. Extract somewhere, e.g. G:\xampp-win32-1.7.0\</li><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">Remove directory G:\xampp\php</li><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">Remove G:\xampp\apache\modules\php5apache2_2.dll and php5apache2_2_filter.dll</li><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">Copy G:\xampp-win32-1.7.0\xampp\php to G:\xampp\php.</li><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">Copy G:\xampp-win32-1.7.0\xampp\apache\bin\php* to G:\xampp\apache\bin</li><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">Edit G:\xampp\apache\conf\extra\httpd-xampp.conf.<br /><ul style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; list-style-image: initial; list-style-position: initial; list-style-type: disc; margin-bottom: 0px; margin-left: 30px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">Immediately after the line, <IfModule alias_module> add the lines</li></ul></li></ol><div style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">(snip)</div><pre class="lang-php prettyprint" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><code style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><IfModule</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="atn" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: red; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">mime_module</span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">></span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /> LoadModule php5_module "/xampp/apache/bin/php5apache2_2.dll"<br /> AddType application/x-httpd-php-source .phps<br /> AddType application/x-httpd-php .php .php5 .php4 .php3 .phtml .phpt<br /> </span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><Directory</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="atv" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">"/xampp/htdocs/xampp"</span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">></span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /> </span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><IfModule</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="atn" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: red; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">php5_module</span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">></span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /> </span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><Files</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="atv" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: blue; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">"status.php"</span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">></span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /> php_admin_flag safe_mode off<br /> </span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"></Files></span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /> </span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"></IfModule></span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /> </span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"></Directory></span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /></span><span class="tag" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: maroon; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"></IfModule></span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><br /></span></code></pre><div style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">(Note that this is taken from the same file in the 1.7.0 xampp distribution. If you run into trouble, check that conf file and make the new one match it.)</div><div style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">You should then be able to start the apache server with PHP 5.2.8. You can tail the G:\xampp\apache\logs\error.log file to see whether there are any errors on startup. If not, you should be able to see the XAMPP splash screen when you navigate to localhost.</div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0Karunagappally, Kerala, India9.054716 76.5353789.039035 76.515637 9.0703970000000016 76.555118999999991tag:blogger.com,1999:blog-7705858543089750008.post-6907158345578385852011-09-01T04:08:00.000-07:002011-09-01T04:10:36.407-07:00Codeigniter Callback Function to validate date.<div dir="ltr" style="text-align: left;" trbidi="on"><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;">function validdate($str){</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> if ( ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $str) ) {</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> $arr = split("-",$str);</span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">// splitting the array</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> $yy = $arr[0]; </span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">//first element of the array is year</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> $mm = $arr[1]; </span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">//second element is month</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> $dd = $arr[2]; </span><span class="Apple-style-span" style="color: #666666; font-family: 'Courier New', Courier, monospace;">//third element is days</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> if( checkdate($mm, $dd, $yy) ); {</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> return true;</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> }</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> }</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> else {</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> $this->form_validation->set_message('validdate', 'Check format of %s field.');</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> return FALSE;</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;"> }</span><br /><span class="Apple-style-span" style="color: #0b5394; font-family: 'Courier New', Courier, monospace;">} </span></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0tag:blogger.com,1999:blog-7705858543089750008.post-495675927286928802011-08-15T03:26:00.000-07:002011-08-15T03:28:17.208-07:00Code Igniter Date Validation Function<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">These two functions i use to validate maximum and minimum values of a date field</span><br /><b><br /></b><br /><b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><b><u>FUNCTION MAXDATE:</u></b></span></b><br /><b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Function Name :</span></b> <span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">maxDate</span><br /><b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Parameters :</span></b><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">$str,$reference,$refName</span><br /><br /><b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Meaning :</span></b><br /> <span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><b>$str</b></span> : <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">This variable is used to pass the variable name used to post the value to be validated</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman';"> </span></span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><b>$reference</b></span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman';"> : </span><span class="Apple-style-span" style="color: black;">This variable is used to pass the value of date that should be the allowable maximum date.</span></span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><b>$refName</b></span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman';"> : </span><span class="Apple-style-span" style="color: black;">This variable is used to pass the name of reference, is Optional</span></span></span></span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"><b>Usage:</b> </span></span></span></span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;">Can be used in two ways</span></span></span></span><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> 1. As call back function to the validation rules of Codeigniter</span><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> Example: </span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> $this->form_validation->set_rules('sessionDate['.$i.']','Date',<span class="Apple-tab-span" style="white-space: pre;"> </span>'trim|callback_maxDate['.$endDate.']|xss_clean');</span><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> 2. As function Call</span><br /><span class="Apple-style-span" style="color: #999999;"> if(!<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">maxDate('startDate','2011-06-23','End Date</span></span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace; font-size: x-small;">')){</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> echo 'Satrt Date Should be Before End Date';</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> }</span><br />---------------------------------------------------------------------<br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">function maxDate($str,$reference,$refName='Reference Date'){</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if ( !preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $reference) ) {</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//WRONG REFERENCE DATE FORMAT</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$this->form_validation->set_message('maxDate', $refName.' is in Unknown Format');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//echo $refName.' is in Unknown Format';</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else if ( !preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $str) ) {</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//WRONG DATE FORMAT</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$this->form_validation->set_message('maxDate', 'The %s shoyuld be in "YYY-MM-DD" Format.');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//echo 'The %s shoyuld be in "YYY-MM-DD" Format.';</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"> </span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$arr = explode("-", $str); // splitting the array</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$yyyy = $arr[0]; // first element of the array is year</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$mm = $arr[1]; // second element is month</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$dd = $arr[2]; // third element is days</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if( !checkdate($mm, $dd, $yyyy) ){</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$this->form_validation->set_message('maxDate', 'The %s is an Invalid Date.');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//echo 'The %s is an Invalid Date.';</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else if(strtotime($str)>strtotime($reference)){</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$this->form_validation->set_message('maxDate', 'The Maximum value of %s should be '.$reference.'.');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//echo 'The Maximum value of %s should be '.$reference.'.';</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br /><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"> </span></span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//echo $this->form_validation->set_message('maxDate', 'The %s is an Invalid Date.');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return true;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"> }</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">-------------------------------------------------------- </span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"></span><br /><a name='more'></a><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"><b><u>FUNCTION MINDATE:</u></b></span></span><br /><div><br /><br /><b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Function Name :</span></b> <span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">minDate</span><br /><b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Parameters :</span></b><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">$str,$reference,$refName</span><br /><br /><b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Meaning :</span></b><br /> <span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><b>$str</b></span> <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">: This variable is used to pass the variable name used to post the value to be validated</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman';"> </span></span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><b>$reference</b></span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"> : This variable is used to pass the value of date that should be the allowable minimum date.</span></span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><b>$refName</b></span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman';"> </span><span class="Apple-style-span" style="color: black;">: This variable is used to pass the name of reference, is Optional</span></span></span></span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"><b>Usage:</b> </span></span></span></span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;"><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="color: black;">Can be used in two ways</span></span></span></span><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> 1. As call back function to the validation rules of Codeigniter</span><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> Example: </span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> $this->form_validation->set_rules('sessionDate['.$i.']','Date',<span class="Apple-tab-span" style="white-space: pre;"> </span>'trim|callback_</span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="font-size: x-small;">minDate</span></span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace; font-size: x-small;">['.$endDate.']|xss_clean');</span><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> 2. As function Call</span><br /><span class="Apple-style-span" style="color: #999999;"> if(!<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">minDate('endDate','2011-06-23','Start Date</span></span><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace; font-size: x-small;">')){</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> echo 'End Date Should be Before Start Date';</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace; font-size: x-small;"> }</span><br /><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"></span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;">function minDate($str,$reference,$refName='Reference Date'){</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if ( !preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $reference) ) {</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//WRONG REFERENCE DATE FORMAT</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$this->form_validation->set_message('minDate', $refName.' is in Unknown Format');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else if ( !preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $str) ) {</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//WRONG DATE FORMAT</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$this->form_validation->set_message('minDate', 'The %s shoyuld be in "YYY-MM-DD" Format.');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"> </span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$arr = explode("-", $str); // splitting the array</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$yyyy = $arr[0]; // first element of the array is year</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$mm = $arr[1]; // second element is month</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$dd = $arr[2]; // third element is days</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if( !checkdate($mm, $dd, $yyyy) ){</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$this->form_validation->set_message('minDate', 'The %s is an Invalid Date.');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else if(strtotime($str)<strtotime($reference)){</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$this->form_validation->set_message('minDate', 'The Minimum value of %s should be '.$reference.'.');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return false;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>//$this->form_validation->set_message('minDate', 'The %s is an Invalid Date.');</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return true;</span><br /><span class="Apple-style-span" style="color: #999999; font-family: 'Courier New', Courier, monospace;"> }</span><br /><br /></div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0tag:blogger.com,1999:blog-7705858543089750008.post-82506126443928087802011-07-06T22:10:00.000-07:002011-07-06T22:10:12.741-07:00Decimal validation using codeigniter form validation class | DSCRIPTS<a href="http://www.dscripts.net/2010/06/20/decimal-validation-using-codeigniter-form-validation-class/">Decimal validation using codeigniter form validation class | DSCRIPTS</a>: "class MY_Form_validation extends CI_Form_validation {<br /> <br /> function decimal($value)<br /> {<br /> $CI =& get_instance();<br /> $CI->form_validation->set_message('decimal',<br /> 'The %s is not a valid decimal number.');<br /> <br /> $regx = '/^[-+]?[0-9]*\.?[0-9]*$/';<br /> if(preg_match($regx, $value))<br /> return true;<br /> return false;<br /> }<br />}"Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0tag:blogger.com,1999:blog-7705858543089750008.post-30548529956756920322011-07-05T00:46:00.000-07:002011-07-05T01:01:04.663-07:00JavaScript: Avoid ajax if not necessary and store small data locally in the page itself<div dir="ltr" style="text-align: left;" trbidi="on"><style type="text/css">.codesnippet{ color:#003366; font-family:"Times New Roman", Times, serif; border:1px solid #E0E0E0; font-family: Georgia, 'Times New Roman', serif; } .commentclass{ color:#888888; font-family:"Times New Roman", Times, serif; font-family: Georgia, 'Times New Roman', serif; } </style><br /><b><span class="Apple-style-span" style="color: #20124d;">Avoid ajax if not necessary and store small data locally in the page itself.</span></b><br /><b><span class="Apple-style-span" style="color: #20124d;">Example Case:</span>We have to custom messages or descriptions on selecting an option of dropdown.</b><br />We can use some attribute like title inside the option tag of select/ Dropdown list to store some custom values/ descriptions and can be used to display the message or text without AJAX.<br /><br /><br />Here i used the following code for storing the currency of each country in the title field of the corresponding option and will be displayed when the country is selected.<br />HTML CODE<br /><br /><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"><table width="100%" class="noBorder" cellpadding="0" cellspacing="0"></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><tr></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><td></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><select name="hostCountry" onchange="showhostcurrency(this);"></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><option value="">COUNTRY</option></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><option title="Rupees" value="1">INDIA</option></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><option title="USD" value="1">USA</option> </span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span></select></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"> <span class="Apple-tab-span" style="white-space: pre;"> </span></td></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><td class="showCurrency"></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"> <span class="Apple-tab-span" style="white-space: pre;"> </span></td></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span></tr></span><br /><span class="Apple-style-span" style="color: #073763; font-family: Georgia, 'Times New Roman', serif;"></table></span><br /><br /><br /><br /><div class="codesnippet" style="text-align: left;"><select name="hostCountry" onchange="showhostcurrency(this);"> <option value="">COUNTRY</option> <option title="Rupees" value="1">INDIA</option> <option title="USD" value="1">USA</option> </select></div><div class="codesnippet" style="text-align: left;">function showhostcurrency(obj){<br /><span class="commentclass">//Here the object will be passed to function which will be recieved to variable obj</span><br /><span class="commentclass">//Value stored in title can be accessed as follows</span><br /> var currency=$(obj).find("option:selected").attr('title');<br /> if(currency!=''){<br /> var currency='Currency: '+currency;<br /> }<br /> $(obj).parent().parent().find('td.showCurrency').html(currency);<br />}</div></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0tag:blogger.com,1999:blog-7705858543089750008.post-6692827060853334552011-07-04T21:58:00.000-07:002011-07-05T00:03:13.673-07:00Custom Functions<div dir="ltr" style="text-align: left;" trbidi="on"><br />I have been using PHP, Javascript, Jquery with codeignitor for the past 2 years. I used to use and make many custom functions for my productions purpose of which some are noteworthy and may be useful for others also.<br />I would like to share and discuss such custom functions with all PHP developers and freshers<br /></div>Mohd Anashttps://plus.google.com/104934280959603812402noreply@blogger.com0