June 30, 2015

How to remove blank/unnecessary lines in dreamweaver?




This type of issue mostly face when you can download any file from FTP/server, because its Fille Zilla setting issue,
That's why in any .php file lost of blank/unnecessary lines you can see in file when open that file in Dreamweaver,

Here's a helpful solution to remove blank/unnecessary line from file using Dreamweaver:


Step 1: Click CTRL + F

Step 2: Select 'Current Document' from Find In options (if you want replace in all files then select specific folder)

Step 3: checked 'Use regular expression' from footer options

Step 4: Type [\r\n]{2,} in 'Find' text-area

Step 5: Type \n in 'Replace' text-area

Step 6: And press Replace All' button from right side



Enjoy!

June 23, 2015

How to Set a Dynamic Width / Height on Fancybox?


Yes it's possible first you can turn off "autoSize" and then set width as "auto":

$.fancybox.open({
    content  : 'Lorem ipsum dolor sit ame',
    autoSize : false,
    width    : "auto",
    height   : "80%"
});​

To see example <a href="http://jsfiddle.net/2VmrG/" target="_blank">click here!</a>

Enjoy!

June 21, 2015

jquery password validation with at least 8 characters, 1 number, 1 upper and 1 lowercase.


Regular expression offers an extremely powerful way of validation for forms password.

I guess your regular expression should look like:


<form id="register">
    <label for="password">Password:</label>
    <input name="password" id="password" type="password"/>
    <span id="result"></span>
</form>

Here is some javascript/jquery code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#password').keyup(function(){
$('#result').html(checkStrength($('#password').val()))
});

function checkStrength(password)
{
//initial strength
var strength1 = 0;
var strength2 = 0;
var strength3 = 0;
var strength4 = 0;

//length is ok, lets continue.
//if length is 8 characters or more, increase strength value
if (password.length < 8) strength1 = 1;
//if password contains both lower and uppercase characters, increase strength value
if (!password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  strength2 = 1;
//if it has numbers and characters, increase strength value
if (!password.match(/([0-9])/))  strength3 = 1;
//if it has one special character, increase strength value
if (!password.match(/([!,%,&,@,#,$,^,*,?,_,~])/))  strength4 += 1
//if it has two special characters, increase strength value
//if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,",%,&,@,#,$,^,*,?,_,~])/)) strength += 1
//now we have calculated strength value, we can return messages
//if value is less than 2

if(strength1==1)
{
$('#result').text('Password too short.');
} else if(strength2==1) {
$('#result').text('Please used upper & lower case letter.');
} else if(strength3==1) {
$('#result').text('Please used number.');
} else if(strength4==1) {
$('#result').text('Please used any special character.');
} else {
$('#result').text('Strong!');
}
}
});
</script>

Enjoy!

June 18, 2015

MySQL: why does "SELECT count()" return a value of array?




There are two solution to get total number of records from any table, Here are both explain in brief:


First one is - you can used COUNT() directly to select query like below e.g.

$Qr=mysql_query('select COUNT(*) from tablename');
$Qry=mysql_fetch_array($Qr);
echo $Qry;

It's display total number of records.

--------------------------


Second one is - 'mysql_num_rows' like below e.g.

$Qr=mysql_query('select * from tablename');
$Qry=mysql_num_rows($Qr);
echo $Qry;

It's display total number of records.



Enjoy!

June 17, 2015

MySQL select query to COUNT only unique values.



If you used join query on parent table and child table and you want to fetch unique records from both table then see the below example

SELECT COUNT(DISTINCT(t1.id)) FROM table1 t1 left join table2 t2 on t2.id=t1.t2id

Enjoy!

jQuery condition to check responsive screen.


Yes, It's possible to check different media screen in jQuery for add condition.

Following example for different screen:

$(window).resize(function(){
   if ($(window).width() <= 300)
   {
       // do something here
   } else if ($(window).width() <= 800){
     // do something here
   } else if ($(window).width() <= 970){
     // do something here
   } else {
     // do something here for desktop full screen
   }
});

Enjoy!

Javascript validation for radio button.

First write HTML with form and multiple radio fields with same name,

Assign different value for each radio. See in below example.

Also set the form name OR id and form on submit call a function, Below is full example:


<form name="frmAdd" id="frmAdd" onsubmit="return chkRegEvent()" >
  <input type="radio" name="filter" id="filter" value="all" /> View All Evemts
  <input type="radio" name="filter" id="filter" value="upcoming" /> Upcoming Events Only
</form>

In below script check radio button checked OR not?


<script>
function chkRegEvent()
{
    var temp=0;
    for(var i=0; i< document.forms.frmAdd.filter.length;i++)
    {
        if(document.forms.frmAdd.filter[i].checked==true)
        {
            temp=1;
            
        }
        
    }
    if(temp==0)
    {
        alert("Please select filter option.");
        return false;
    }
}
</script>

In alert you should set any message you want.

Enjoy!

June 16, 2015

PHP: Convert text file into XML.

Here is perfect example to convert text file into XML.

abc.txt file content is:

Nokia
Samsung
Micromax

If you want to conver this text file into XML formate like this:

<data>
<mobilestore>Sony</mobilestore>
<mobilestore>Pioneer</mobilestore>
<mobilestore>Boss</mobilestore>
</data>

Solution


First I used file() function for opening the file.

Then used DOMDocument for build the XML structure.

And last file_put_contents() function for saving he result XML file.

If you want exact example then please see here: http://stackoverflow.com/questions/6741251/convert-text-file-contents-to-xml

Enjot!


PHP: how to play all type of vides using tag?


PHP: how to play all type of videos using tag?

The HTML have a <video></video> tag for playing the .mp4 video.


<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  <source src="movie.webm" type="video/webm">
</video>

Now If you have not above three type of video then don't warry.

You shoude convert video in above three (mp4, ogg, webm) formate from here: http://video.online-convert.com/

HTML - Video browser supported table:


Browser MP4 WebM Ogg
Internet Explorer YES NO NO
Chrome YES YES YES
Firefox YES YES YES
Safari YES NO NO

Enjoy!

MySQL: PHP register script not working.


It's simple sript to select OR insert query with MySQL.

I copied the example from the PHP documentation.


<?php
    $sql='Type here any select OR insert query';
    $result = mysql_query($sql);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }
    mysql_close();
?>

For more result Click Here!

Enjoy!

PHP: session is unchangeable from user end?

In PHP session saved in the server side, So any user can't change/modify.

But cookie stored in the browser usually PHPSESSID which identifies which server session the user is using.

See more result: https://stackoverflow.com/questions/30772402/is-php-session-unchangeable-from-user-end

Enjoy!

June 13, 2015

How to remove related videos from the end of YouTube video?


If you directly copy embedded code of any YouTube video and if used that code in your website then after end of that video its display related videos.

If you don't want that type of related video then please follow this step:




Under that code there some check boxes for optional, so please  unchecked: 'Show suggested video when the video finishes'.



Then video URL look like this: http://www.youtube.com/embed/videocode?rel=0

Enjoy!


June 11, 2015

Joomla: Error 500 : Internal Server Error




I face these type of issue in past and I have one solution:

First remove the .htaccess from root folder.

And then also remove everything  from .htaccess from administrator folder and its working perfectly.

Enjoy!

June 10, 2015

PHP list() function example

Below is the PHP list() function with example:

<!DOCTYPE html>
<html>
<body>

<?php
$my_array = array("car","bike","cycle");

list($a, , $c) = $my_array;
echo "This is the $a and $c variables.";
?>

</body>
</html>

Output is:

This is the car, bike, cycle.

Enjoy!

June 9, 2015

PHP function example


How to call simple function in PHP?

<?php
function firstMsg();() {
     echo "Welcome to Blog";
}

echo firstMsg();

June 4, 2015

PHP how to get total days between two date?



Following calculation for get total days between two difference date:

<?php
$dt1=date_create("2015-06-01");
$dt2=date_create("2015-06-04");
$diff=date_diff($dt1,$dt2);

echo $diff;

//Output
+3 days
?>


Enjoy!


June 2, 2015

OpenCart set only one item in cart.


If you want to display only one item in cart and the add more OR update cart quantity then follow below step:

1. First edit System / library / cart.php file

2. Find below code:
$this->session->data['cart'][$key] += (int)$qty;

3. Replace with this one:
$this->session->data['cart'][$key] = (int)$qty;

So its not update cart quantity.

Enjoy!

June 1, 2015

OpenCart how to change home page slider images?



You can easily change home page slider images from admin.

- First please login in admin sitename/admin with username and password.

- Go to System -> Design -> Banner and select your home page banner and edit it to change images.

Enjoy!

Integrating Google reCAPTCHA v3 in HTML Form with PHP

  What is Google reCAPTCHA v3? Google reCAPTCHA is a free service that helps protect websites from spam and abuse. reCAPTCHA v3 is the lates...