function seo($input)
{
    //remove single quote and dash
    $input = str_replace(array("'", "-"), "", $input); 

    //convert to lowercase
    $input = mb_convert_case($input, MB_CASE_LOWER, "UTF-8"); 

    //replace everything non an with dashes
    $input = preg_replace("#[^a-zA-Z0-9]+#", "-", $input); 

    //replace multiple dashes with one
    $input = preg_replace("#(-){2,}#", "$1", $input);

    //trim dashes from beginning and end of string if any
    $input = trim($input, "-"); 
    
    //voila
    return $input; 
}

OP:
echo seo(“Tom’s Fish & Chips”); //toms-fish-chips
echo seo(“1-2-3 Pizza”); //123-pizza

The below function takes array element which needs to be removed as parameter as below

ary.remove(‘One’);
var ary = [‘One’, ‘Two’, ‘Three’];
Array.prototype.remove = function() {
    var what, a = arguments, L = a.length, ax;
    while (L && this.length) {
        what = a[--L];
        while ((ax = this.indexOf(what)) !== -1) {
            this.splice(ax, 1);
        }
    }
    return this;
};

The above method works perfectly works for java script array with strings in it.

For the below variable

var csvEmpIds = ‘1,2,3,4,5’;
arrEmpIds = csvEmpIds.split(‘,’);
ary.remove(2);

The above will not work as you should pass 2 as a string and split function creates
a array by splitting from one variable and putting as a strings in array.

so csvEmpIds.split(‘,’) will create array like below

arrEmpIds = ['1','2','3','4','5'];

In this case to remove element from array which you got by splitting come delimited value you should
do as below.

ary.remove('2');

To Remove array which is declared globally use the below function

var ary = ['three', 'seven', 'eleven'];
removeA(ary, 'seven');
function removeA(arr)
{
  var what, a = arguments, L = a.length, ax;
  
  while (L > 1 && arr.length) 
  {
    what = a[--L];
    while ((ax= arr.indexOf(what)) !== -1) 
    {
      arr.splice(ax, 1);
    }
   }

   return arr;
}

HTTP Cookies are not a feature of PHP, nor a feature of Javascript : those are just programming languages that allow a developper to manipulate them.

The biggest difference between JS and PHP is that :

Javascript runs on the client side
PHP runs on the server side

But cookies are still the same : they are defined as a standard — see RFC 2965.

Still, note that modern browsers implement cookies that are not accessible from Javascript (see the httponly option of setcookie) — which means that, depending on the browser, and the way a cookie was set, it might not be accessible from Javascript.

This is a security measure — and is not a difference between “js cookies” and “php cookies” : it’s just a property of some cookies.

Create session cookie

  $.cookie('CookieName', 'Value');

Cookie that Expires in 7 days

 $.cookie('CookieName', 'Value', { expires: 7 });

Create cookie valid across entire site:

  $.cookie('CookieName', 'Value', { expires: 7, path: '/' });

Read value cookie:

 $.cookie('the_cookie'); // => "the_value"
 $.cookie('not_existing'); // => null

Delete cookie:

 // Returns true when cookie was found, false when no cookie was found...
 $.removeCookie('the_cookie');

 // Same path as when the cookie was written...
 $.removeCookie('the_cookie', { path: '/' });
CREATE TABLE `fruits` (
      `fruit_id` int(11) default NULL,
      `fruit_name` varchar(255) collate latin1_general_ci default NULL
    );

INSERT INTO fruits(fruit_id, fruit_name) 
          VALUES (101, 'Mango'),
                 (102, 'Apple'),
                 (103, 'Orange'),
                 (104, 'Pineapple'),
                 (105, 'Lemon'),
                 (106, 'Custard');
SELECT row
  FROM (SELECT fruit_id, CAST(fruit_id AS CHAR(255)) row
          FROM fruits
        UNION
        SELECT fruit_id, CAST(fruit_name AS CHAR(255)) row
          FROM fruits) s
 WHERE fruit_id = 101;

Output

 101
 Mango 
//function for converting string into indian currency format
    function intToFormat(nStr)
    {
     nStr += '';
     x = nStr.split('.');
     x1 = x[0];
     x2 = x.length > 1 ? '.' + x[1] : '';
     var rgx = /(d+)(d{3})/;
     var z = 0;
     var len = String(x1).length;
     var num = parseInt((len/2)-1);
 
      while (rgx.test(x1))
      {
        if(z > 0)
        {
          x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        else
        {
          x1 = x1.replace(rgx, '$1' + ',' + '$2');
          rgx = /(d+)(d{2})/;
        }
        z++;
        num--;
        if(num == 0)
        {
          break;
        }
      }
     return x1 + x2;
    }

I have a real estate website where people can search property based on Location, Property Type and Builder.

I have a Table like below.

CREATE TABLE Project(ProjectId INT NOT NULL PRIMARY KEY AUTO_INCREMENT, 
                     Location  VARCHAR(255), 
                     PropertyType VARCHAR(255), 
                     Builder VARCHAR(255), 
                     ProjectName  VARCHAR(255),
                     Status TINYINT)
                     
                     
INSERT INTO Project(Location, PropertyType, Builder, ProjectName)
             VALUES('Location A', 'Flats',     'Builder A', 'Project A', 1),
                   ('Location A', 'Villas',    'Builder B', 'Project B', 1),
                   ('Location B', 'Flats',     'Builder A', 'Project C', 1),
                   ('Location C', 'Villas',    'Builder C', 'Project D', 1),
                   ('Location B', 'Plots',     'Builder B', 'Project E', 1),
                   ('Location A', 'Row House', 'Builder C', 'Project F', 1),
                   ('Location A', 'Plots',     'Builder A', 'Project G', 1),
                   ('Location C', 'Plots',     'Builder C', 'Project H', 1),
                   ('Location C', 'Flats',     'Builder B', 'Project I', 1),
                   ('Location C', 'Villas',    'Builder B', 'Project J', 1),
                   ('Location A', 'Villas',    'Builder A', 'Project K', 1),
                   ('Location C', 'Flats',     'Builder B', 'Project L', 1);

The search procedure which I use is in such a way that It brings back search result as per the parameters they selected i.e Property Type, Location, Builder Name

Now there may be projects for some search parameters as below

Flats by Builder A at Location C

I want to change procedure in such a way the parameters in filters in where clause should change to bring result all the time by considering other possibilities like for the above

Flats by Builder A at Location C

There is no Flats by Builder A at Location C so it should display Flats at Location C by Other Builders

Location C   Flats     Builder B    Project I

The Filter should Consider PropertyType, Location and Builder Name

Villas at Location B

There is No Villas at Location B So

Location A    Villas   Builder B   Project B
Location C    Villas   Builder B   Project J
Location A    Villas   Builder A   Project K

The search should happen by

PropertyType -> Location -> Builder

If there is No project for a particular Builder in that Location then

PropertyType -> Location

If there is No project for a particular Location then

PropertyType

The parameters in the filters should be eliminated in such a way it brings similar result to search param.


       PropertyType -> Location -> Builder       No Records
       PropertyType -> Location                  No Records
       PropertyType                              Records Found

Solution

DROP PROCEDURE  IF EXISTS getProjectResult;
CREATE PROCEDURE getProjectResult(IN PropertyType VARCHAR(255), IN Location VARCHAR(255), IN BuilderName VARCHAR(255))
BEGIN
  DROP TABLE IF EXISTS tblTempProjIds;
  CREATE TEMPORARY TABLE tblTempProjIds(ProjId INT, Points INT);
  
  SET @PropertyTypePoints = 0;
  SET @LocationPoints     = 0;
  SET @BuilderName        = 0;
  
  IF PropertyType  '' THEN
    SET @PropertyTypePoints = 5;
  END IF;
  
  IF Location  '' THEN
    SET @LocationPoints = 3;
  END IF;
  
  IF BuilderName  '' THEN
    SET @BuilderName = 1;
  END IF;
  
  SET @BestScore = @PropertyTypePoints + @LocationPoints + @BuilderName;
  
  SET @strSQL ='INSERT INTO tblTempProjIds(ProjId, Points) SELECT ProjectId,
                       CASE WHEN PropertyType= ? then 5 else 0 end + 
                       CASE WHEN Location = ? then 3 else 0 end +  
                       CASE WHEN Builder = ? then 1 else 0 end as score
                  FROM project
                 ORDER BY score DESC';
                   
  SET @PropertyType = PropertyType;
  SET @Location     = Location;
  SET @BuilderName  = BuilderName;
  
  PREPARE stmt FROM @strSQL;
  EXECUTE stmt USING @PropertyType, @Location, @BuilderName;  
  DEALLOCATE PREPARE stmt; 
  
  #SELECT * FROM tblTempProjIds;
  
  SET @strSQLCount ='SELECT @Num := MAX(Points) 
                       FROM tblTempProjIds';
                      
                 
  PREPARE stmt FROM @strSQLCount;
  EXECUTE stmt;  
  DEALLOCATE PREPARE stmt;  
  
  
  CASE @Num 
     WHEN 9 THEN SET @Where = CONCAT(' AND PropertyType="', PropertyType, '" AND Location="', Location, '" AND Builder="', BuilderName, '"');     
     WHEN 8 THEN SET @Where = CONCAT(' AND PropertyType="', PropertyType, '" AND Location="', Location, '"');     
     WHEN 6 THEN SET @Where = CONCAT(' AND PropertyType="', PropertyType, '" AND Builder ="', BuilderName, '"'); 
     WHEN 5 THEN SET @Where = CONCAT(' AND PropertyType="', PropertyType, '"'); 
     WHEN 4 THEN SET @Where = CONCAT(' AND Location="', Location, '" AND Builder ="', BuilderName, '"');
     WHEN 3 THEN SET @Where = CONCAT(' AND Location="', Location, '"');
     WHEN 1 THEN SET @Where = CONCAT(' AND Builder="', BuilderName, '"'); 
     WHEN 0 THEN SET @Where = '';
   END CASE;
   
   
    SET @FinalSQL =    CONCAT('SELECT * 
                                 FROM project
                                WHERE status = 1 ', @Where);
                            
    PREPARE stmt FROM @FinalSQL;
    EXECUTE stmt;  
    DEALLOCATE PREPARE stmt;             
END;