Announcement

Collapse
No announcement yet.

Third time lucky?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Third time lucky?

    Hi

    Nobody answered my previous 2 threads, but I have moved on, even if I did not get anywhere...


    I have a php script that queries a MySQL database. It woks fine.However, I want it to strip queries of foreign accents as all records have ignored them Google style. For instance of someone enters the Frencvh town "Svres" it should be recognized at the server as "Sevres" without the accent. At the moment I get a null result showing that waht was earched was "Svres", i.e. the letter with the accent rather than changing to one without, simply gets deleted.


    I have, amongst other things followed advice regarding the character set. utf8 does not cater for accents and utf8mb4 seems to be part of the solution. As such I modified the database accordingly following instructions on this page https://mathiasbynens.be/notes/mysql-utf8mb4 but it still does not work.
    I suspect that the problem is in the script or the way the data is uploaded to the table. I think that some sort of code should be added to the script to specify the charcter set, and I have found something that might help, although being ignorant of both php and MySQL I don't know how to use it or where to insert it


    mysql_query("SET NAMES 'utf8'"); (this need to be changed tomsqli, I think)

    IThen , there is a question over the way the data was collected and sent to the server. I used Notepad and then the CSVed programme to convert it into the format acceptable by the database, but there is a possibility that even though in csv it may be ANSI rather than utf8, and I don't know how to find out.


    I am pasting below part of the script in case you can tell me how to modify the line of code above and here to place it. And you can see and test the Search boc in this page http://pintotours.net/Europe/Spain/airportBcn.html Enter "Svres" with the accent.

    Thank you

    Code:
    <?php
    $results = true;
    
    // Find out if the user accessed the file directly
    //if($_SERVER['REQUEST_METHOD'] == 'GET') {
    
      //  header('Location:Search1.php'); // redirect the user if the form was not submitted.
      // die(); // Ignore anything after the die.
    
    //} elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
    
    	## this is a much neater method of detecting post, nothing posted, send them on their way	
    if(!isset($_POST)){
    	header('Location:http://pintotours.net/Search/Search1.php'); // redirect the user if the form was not submitted.
        die(); // Ignore anything after the die. 
    
    }
    
    
    
    // Your database preferences
    // We are using constants instead of variables for this
    // You can use either or
    define('HOST', 'localhost'); // Database host
    define('pintotou_******', 'root'); // Database username
    define('*****', 'root'); // Database password
    define('pintotou_search', ''); // Database
    
    $mysqli = new mysqli('localhost', 'pintotou_*****', '*****', 'pintotou_search'); // Connect to the database using MySQLi_* OOP and constants
    if($mysqli->connect_errno) {
        // Do not die or display any MySQL errors in this area.
        die('Unable to connect to the mysql server');
    }
    
    $searchq = filter_var("%{$_POST['keyword']}%", FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); // Sanitize the string
    
    
    $searchq = str_replace( '-', ' ', $searchq );
    
    
    $sql = "SELECT Image, Chain, Country, City, Top as '', Medium as '', Low as '' FROM Chains WHERE Country LIKE ? OR City LIKE ?"; // Your query string
    
    
    
    $prepare = $mysqli->prepare($sql); // Prepare your query string
    
    
    
    
    
    
    
    $prepare->bind_param('ss', $searchq, $searchq); // Bind the placeholders to your search variables
    // s = string | i = integer | d = double | b = blob
    $prepare->execute(); // Execute the prepared statement
    
    
    
    $prepare->store_result(); // Store the results for later checking
    
    // Use num_rows to check if the results return a 0 or 1. 0 meaning false and 1 meaning true
    if($prepare->num_rows) {
    
        $prepare->bind_result($image, $chain, $country, $city, $top, $medium, $low); // Append variables to the columns you specified
    }else
    {
    	$results = false;
    $searchMsg = 'There were no search results for &lsquo;'. $searchq .'&rsquo;!';
    }
    if(strlen(trim($_POST['keyword'])) <= 3) 
    {
    	$results = false;
    	$searchMsg = 'Please enter at least 3 characters';
    }
    ?>

  • #2
    Hi qim,

    Sorry no-one responded previously , I'm somewhat of a missing person myself sometimes!
    A quick and dirty solution might be to write a method that replaces all the characters? (i say quick 'n' dirty, but it's probably not very quick to assign all the new characters to the new character values!)
    You could use this link as a reference for it

    if you change the character set to support the character then you'll encounter an issue where the string will actually be searching for "Svres"

    so the following would be a basis for a solution?

    Code:
    $sql = removeSpecialChars($sql);

    Code:
    function removeSpecialChars($str) {
        $unwanted_array = array(    'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'C', ''=>'E', ''=>'E',
                                ''=>'E', ''=>'E', ''=>'I', ''=>'I', ''=>'I', ''=>'I', ''=>'N', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'U',
                                ''=>'U', ''=>'U', ''=>'U', ''=>'Y', ''=>'B', ''=>'Ss', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'c',
                                ''=>'e', ''=>'e', ''=>'e', ''=>'e', ''=>'i', ''=>'i', ''=>'i', ''=>'i', ''=>'o', ''=>'n', ''=>'o', ''=>'o', ''=>'o', ''=>'o',
                                ''=>'o', ''=>'o', ''=>'u', ''=>'u', ''=>'u', ''=>'y', ''=>'b', ''=>'y' );
    return strtr( $str, $unwanted_array );
    }
    found a nice post on SO for it.


    Alternatively you could implement a UDF within MySQL to do the same thing?

    Code:
    CREATE FUNCTION sf_RemoveExtraChars (@NAME nvarchar(50))
    RETURNS nvarchar(50)
    AS
    BEGIN
      declare @TempString nvarchar(100)
      set @TempString = @NAME 
      set @TempString = LOWER(@TempString)
      set @TempString =  replace(@TempString,'Š','S')
       set @TempString =  replace(@TempString,'š','s')
       set @TempString =  replace(@TempString,'Ž','Z')
       set @TempString =  replace(@TempString,'ž','z')
       set @TempString =  replace(@TempString,'','A')
       set @TempString =  replace(@TempString,'','A')
       set @TempString =  replace(@TempString,'','A')
       set @TempString =  replace(@TempString,'','A')
       set @TempString =  replace(@TempString,'','A')
       set @TempString =  replace(@TempString,'','A')
       set @TempString =  replace(@TempString,'','A')
       set @TempString =  replace(@TempString,'','C')
       set @TempString =  replace(@TempString,'','E')
       set @TempString =  replace(@TempString,'','E')
       set @TempString =  replace(@TempString,'','E')
       set @TempString =  replace(@TempString,'','E')
       set @TempString =  replace(@TempString,'','I')
       set @TempString =  replace(@TempString,'','I')
       set @TempString =  replace(@TempString,'','I')
       set @TempString =  replace(@TempString,'','I')
       set @TempString =  replace(@TempString,'','N')
       set @TempString =  replace(@TempString,'','O')
       set @TempString =  replace(@TempString,'','O')
       set @TempString =  replace(@TempString,'','O')
       set @TempString =  replace(@TempString,'','O')
       set @TempString =  replace(@TempString,'','O')
       set @TempString =  replace(@TempString,'','O')
       set @TempString =  replace(@TempString,'','U')
       set @TempString =  replace(@TempString,'','U')
       set @TempString =  replace(@TempString,'','U')
       set @TempString =  replace(@TempString,'','U')
       set @TempString =  replace(@TempString,'','Y')
       set @TempString =  replace(@TempString,'','B')
       set @TempString =  replace(@TempString,'','Ss')
       set @TempString =  replace(@TempString,'','a')
       set @TempString =  replace(@TempString,'','a')
       set @TempString =  replace(@TempString,'','a')
       set @TempString =  replace(@TempString,'','a')
       set @TempString =  replace(@TempString,'','a')
       set @TempString =  replace(@TempString,'','a')
       set @TempString =  replace(@TempString,'','a')
       set @TempString =  replace(@TempString,'','c')
       set @TempString =  replace(@TempString,'','e')
       set @TempString =  replace(@TempString,'','e')
       set @TempString =  replace(@TempString,'','e')
       set @TempString =  replace(@TempString,'','e')
       set @TempString =  replace(@TempString,'','i')
       set @TempString =  replace(@TempString,'','i')
       set @TempString =  replace(@TempString,'','i')
       set @TempString =  replace(@TempString,'','i')
       set @TempString =  replace(@TempString,'','o')
       set @TempString =  replace(@TempString,'','n') 
       set @TempString =  replace(@TempString,'','o')
       set @TempString =  replace(@TempString,'','o')
       set @TempString =  replace(@TempString,'','o') 
       set @TempString =  replace(@TempString,'','o')
       set @TempString =  replace(@TempString,'','o')
       set @TempString =  replace(@TempString,'','o') 
       set @TempString =  replace(@TempString,'','u')
       set @TempString =  replace(@TempString,'','u')
       set @TempString =  replace(@TempString,'','u')
       set @TempString =  replace(@TempString,'','y') 
       set @TempString =  replace(@TempString,'','b')
       set @TempString =  replace(@TempString,'','y')
      return @TempString
    END
    GO
    And then implement it within your proc?

    Code:
    /* IF your table does NOT contain any of the diatrics. */
    SELECT * FROM Table
    WHERE title = sf_RemoveExtraChars('Svres')
    
    /* IF your table does contain diatrics. */
    SELECT * FROM Table
    WHERE  sf_RemoveExtraChars(title) = sf_RemoveExtraChars('Svres')
    Last edited by sbeynon; 12-15-2015, 05:21 AM. Reason: added MySQL Function solution
    Who needs a Signature?

    Comment


    • #3
      Hi sbeynon

      Many thanks for trying to save my life...

      I am going to try the first option and see if it resolves the matter.

      The second give me the impression that I just want to change the one city 'Svres'. That's not the case; there are dozens and there will ne hundreds of cities in the database with accents (mainly grave/acute/circumflex/tilde, and letters like c with cedilla and the Spanish )

      Before I change everything I wonder if you could give me your opnion regarding the current cide which I feel from reading extensively needs 2 things:

      change the character set in the html, ie. from <meta charset="utf8"> to <meta charset="utf8mb4">

      and also setting the collation etc after you establish a connection to the database

      which might be something like mysql_query("SET NAMES 'utf8'");

      is this valid code? I tried separately and it did not work but might be because in particular the mysql should be the equivalent translation for mysqli

      can you help there, please?

      Comment


      • #4
        Hi qim

        both the solutions posted achieve the EXACT same thing, they just utilize different technologies.

        One is PHP and one is MySQL

        The issue i gathered you were having is that when someone makes a search say for "Svres" it then moves onto the SQL stage where is sits there as "Svres", as such you require an intermediary step to make it so that the character "" is converted to "e"? (or whatever dependent on the specific character passed through).

        So i found a solution in PHP for you that would convert most (probably not all) characters with diatrics to their equivalent non-diatric character, i then manipulated it to create a second solution being the MySQL one.

        Just to re-iterate; both of these will have the SAME effect, other than if you use the MySQL version you can also run the function against any values coming from the database table hence the

        Code:
        WHERE function(code) = function(data)
        which some might argue makes it worth using in the database, although you could run a cron job or a scheduled task to call activate a php file that runs the php version on the database (but that's a fun little park we can avoid for now )

        Q2 :
        To run an additional query you should use

        Code:
        $mysqli->query($sqlQuery);

        Tidbit :
        The changing of collation probably won't help with the specific issue you've highlighted to me and the solution you asked for.

        Although it may, if you're lucky allow you to pass through the diatric values.

        Although UTF-8 should be fine for that anyway...

        collation wise i'd suggest trying "latin1_general_ci" as it should support ALOT if not most of the characters
        Last edited by sbeynon; 12-15-2015, 06:21 AM.
        Who needs a Signature?

        Comment


        • #5
          Hi thanks

          I used your code in the script but it does not work.

          What did I do wrong?

          Code:
          if($mysqli->connect_errno) {
              // Do not die or display any MySQL errors in this area.
              die('Unable to connect to the mysql server');
          }
          
          $searchq = filter_var("%{$_POST['keyword']}%", FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); // Sanitize the string
          
          
          $searchq = str_replace( '-', ' ', $searchq );
          $sql = removeSpecialChars($sql);
          function removeSpecialChars($str) {
              $unwanted_array = array(    ''=>'S', ''=>'s', ''=>'Z', ''=>'z', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'C', ''=>'E', ''=>'E',
                                      ''=>'E', ''=>'E', ''=>'I', ''=>'I', ''=>'I', ''=>'I', ''=>'N', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'U',
                                      ''=>'U', ''=>'U', ''=>'U', ''=>'Y', ''=>'B', ''=>'Ss', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'c',
                                      ''=>'e', ''=>'e', ''=>'e', ''=>'e', ''=>'i', ''=>'i', ''=>'i', ''=>'i', ''=>'o', ''=>'n', ''=>'o', ''=>'o', ''=>'o', ''=>'o',
                                      ''=>'o', ''=>'o', ''=>'u', ''=>'u', ''=>'u', ''=>'y', ''=>'b', ''=>'y' );
          return strtr( $str, $unwanted_array );
          }
          
          $sql = "SELECT Image, Chain, Country, City, Top as '', Medium as '', Low as '' FROM Chains WHERE Country LIKE ? OR City LIKE ?"; // Your query string
          
          
          
          $prepare = $mysqli->prepare($sql); // Prepare your query string
          
          
          
          
          
          
          
          $prepare->bind_param('ss', $searchq, $searchq); // Bind the placeholders to your search variables
          // s = string | i = integer | d = double | b = blob
          $prepare->execute(); // Execute the prepared statement
          
          
          
          $prepare->store_result(); // Store the results for later checking
          
          // Use num_rows to check if the results return a 0 or 1. 0 meaning false and 1 meaning true
          if($prepare->num_rows) {
          
              $prepare->bind_result($image, $chain, $country, $city, $top, $medium, $low); // Append variables to the columns you specified
          }else
          {
          	$results = false;
          $searchMsg = 'There were no search results for &lsquo;'. $searchq .'&rsquo;!';
          }
          if(strlen(trim($_POST['keyword'])) <= 3) 
          {
          	$results = false;
          	$searchMsg = 'Please enter at least 3 characters';
          }
          ?>

          Comment


          • #6
            At the time you called the function the $sql variable is still null


            try this

            Code:
            <?php
            function removeSpecialChars($str) {
                $unwanted_array = array(
            		'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'C', ''=>'E', ''=>'E',
            		''=>'E', ''=>'E', ''=>'I', ''=>'I', ''=>'I', ''=>'I', ''=>'N', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'U',
            		''=>'U', ''=>'U', ''=>'U', ''=>'Y', ''=>'B', ''=>'Ss', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'c',
            		''=>'e', ''=>'e', ''=>'e', ''=>'e', ''=>'i', ''=>'i', ''=>'i', ''=>'i', ''=>'o', ''=>'n', ''=>'o', ''=>'o', ''=>'o', ''=>'o',
            		''=>'o', ''=>'o', ''=>'u', ''=>'u', ''=>'u', ''=>'y', ''=>'b', ''=>'y' 
            	);
            	return strtr( $str, $unwanted_array );
            }
            
            if($mysqli->connect_errno) {
                // Do not die or display any MySQL errors in this area.
                die('Unable to connect to the mysql server');
            }
            
            $searchq = filter_var("%{$_POST['keyword']}%", FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); // Sanitize the string
            $searchq = str_replace( '-', ' ', $searchq );
            
            $sql = "SELECT Image, Chain, Country, City, Top as '', Medium as '', Low as '' FROM Chains WHERE Country LIKE ? OR City LIKE ?"; // Your query string
            
            
            
            $prepare = $mysqli->prepare($sql); // Prepare your query string
            
            $prepare->bind_param('ss', $searchq, $searchq); // Bind the placeholders to your search variables
            // s = string | i = integer | d = double | b = blob
            $sql = removeSpecialChars($sql);
            $prepare->execute(); // Execute the prepared statement
            
            $prepare->store_result(); // Store the results for later checking
            
            // Use num_rows to check if the results return a 0 or 1. 0 meaning false and 1 meaning true
            if($prepare->num_rows) {
            
                $prepare->bind_result($image, $chain, $country, $city, $top, $medium, $low); // Append variables to the columns you specified
            }
            else
            {
            	$results = false;
            	$searchMsg = 'There were no search results for &lsquo;'. $searchq .'&rsquo;!';
            }
            
            if(strlen(trim($_POST['keyword'])) <= 3) 
            {
            	$results = false;
            	$searchMsg = 'Please enter at least 3 characters';
            }
            ?>
            Who needs a Signature?

            Comment


            • #7
              Also bugger that i didn't notice this before!

              if a requirement if that the string is 3 characters or greater than you should do the check

              Code:
              if(strlen(trim($_POST['keyword'])) <= 3) 
              {
              	$results = false;
              	$searchMsg = 'Please enter at least 3 characters';
              }
              at the top of the page as it means that the WHOLE script doesn't have to run and you avoid any bandwidth or processing used by the database by getting to that point at the start rather than AFTER everything has already run.
              Who needs a Signature?

              Comment


              • #8
                Hi

                I've put that bit at the top of the file but still no good. That code is only for IE9 and IE8 as all other browsers do not allow more less than 3 letter due to the html code
                Code:
                  <input type="text" class="textinput" pattern=".{3,}" required title="3 characters minimum required" placeholder="Enter destination" name="keyword" id="keyword" size="20">

                See in: http://pintotours.net/

                The top of the file looks like this now:

                Code:
                <?php
                $results = true;
                
                if(strlen(trim($_POST['keyword'])) <= 3) 
                {
                	$results = false;
                	$searchMsg = 'Please enter at least 3 characters';
                }
                
                // Find out if the user accessed the file directly
                //if($_SERVER['REQUEST_METHOD'] == 'GET') {
                
                  //  header('Location:Search1.php'); // redirect the user if the form was not submitted.
                  // die(); // Ignore anything after the die.
                
                //} elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
                
                	## this is a much neater method of detecting post, nothing posted, send them on their way	
                if(!isset($_POST)){
                	header('Location:http://pintotours.net/Search/Search1.php'); // redirect the user if the form was not submitted.
                    die(); // Ignore anything after the die. 
                
                }
                Thank you for your patience
                Last edited by qim; 12-15-2015, 07:26 AM.

                Comment


                • #9
                  You can see the structure of the MySQL table here

                  http://pintotours.net/TEMP/upload.html

                  Comment


                  • #10
                    The code i've provided works fine, just tested it.

                    Must be an issue elsewhere, Where is the $mysqli variable being created? - Nevermind found it
                    Last edited by sbeynon; 12-15-2015, 08:20 AM.
                    Who needs a Signature?

                    Comment


                    • #11
                      The code i've provided works fine, just tested it.
                      Did you test on my page?

                      Where is the $mysqli variable being created?
                      Do you mean the query? If so, on severtal pages like the index page I mentioned above.

                      I am going to paste the whole file/script in the same url I gave you above for the MySQL staructure.

                      I am totally lost....

                      Comment


                      • #12
                        Ok try this and look at "View source" for the code

                        http://pintotours.net/TEMP/upload.html

                        Comment


                        • #13
                          The code you are using should be this

                          Code:
                          <?php
                          // function declarations
                          
                          function removeSpecialChars($str) {
                              $unwanted_array = array(    'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'C', ''=>'E', ''=>'E',
                                                      ''=>'E', ''=>'E', ''=>'I', ''=>'I', ''=>'I', ''=>'I', ''=>'N', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'U',
                                                      ''=>'U', ''=>'U', ''=>'U', ''=>'Y', ''=>'B', ''=>'Ss', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'c',
                                                      ''=>'e', ''=>'e', ''=>'e', ''=>'e', ''=>'i', ''=>'i', ''=>'i', ''=>'i', ''=>'o', ''=>'n', ''=>'o', ''=>'o', ''=>'o', ''=>'o',
                                                      ''=>'o', ''=>'o', ''=>'u', ''=>'u', ''=>'u', ''=>'y', ''=>'b', ''=>'y' );
                          	return strtr( $str, $unwanted_array );
                          }
                          //application work
                          $results = true;
                          
                          if(strlen(trim($_POST['keyword'])) <= 3) 
                          {
                          	$results = false;
                          	$searchMsg = 'Please enter at least 3 characters';
                          }
                          
                          
                          // Find out if the user accessed the file directly
                          //if($_SERVER['REQUEST_METHOD'] == 'GET') {
                          
                            //  header('Location:Search1.php'); // redirect the user if the form was not submitted.
                            // die(); // Ignore anything after the die.
                          
                          //} elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
                          
                          // this is a much neater method of detecting post, nothing posted, send them on their way	
                          if(!isset($_POST)){
                          	header('Location:http://pintotours.net/Search/Search1.php'); // redirect the user if the form was not submitted.
                              die(); // Ignore anything after the die. 
                          
                          }
                          
                          
                          
                          // Your database preferences
                          // We are using constants instead of variables for this
                          // You can use either or
                          define('HOST', 'localhost'); // Database host
                          define('pintotou_******', 'root'); // Database username
                          define('*****', 'root'); // Database password
                          define('pintotou_search', ''); // Database
                          
                          $mysqli = new mysqli('localhost', 'pintotou_*****', '*****', 'pintotou_search'); // Connect to the database using MySQLi_* OOP and constants
                          if($mysqli->connect_errno) {
                              // Do not die or display any MySQL errors in this area.
                              die('Unable to connect to the mysql server');
                          }
                          
                          $searchq = filter_var("%{$_POST['keyword']}%", FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); // Sanitize the string
                          
                          $searchq = str_replace( '-', ' ', $searchq );
                          
                          $sql = "SELECT Image, Chain, Country, City, Top as '', Medium as '', Low as '' FROM Chains WHERE Country LIKE ? OR City LIKE ?"; // Your query string
                          
                          
                          
                          $prepare = $mysqli->prepare($sql); // Prepare your query string
                          
                          $prepare->bind_param('ss', $searchq, $searchq); // Bind the placeholders to your search variables
                          // s = string | i = integer | d = double | b = blob
                          $sql = removeSpecialChars($sql);
                          
                          $prepare->execute(); // Execute the prepared statement
                          
                          $prepare->store_result(); // Store the results for later checking
                          
                          // Use num_rows to check if the results return a 0 or 1. 0 meaning false and 1 meaning true
                          if($prepare->num_rows) {
                          
                              $prepare->bind_result($image, $chain, $country, $city, $top, $medium, $low); // Append variables to the columns you specified
                          }else
                          {
                          	$results = false;
                          $searchMsg = 'There were no search results for &lsquo;'. $searchq .'&rsquo;!';
                          }
                          
                          ?>
                          Last edited by sbeynon; 12-15-2015, 08:32 AM.
                          Who needs a Signature?

                          Comment


                          • #14
                            Hi

                            I substituted the whole of the initial php (up to the start of the html) an still the same:

                            It deletes the letter rather than changing it to one without accent.

                            One thing that maybe should be borned in mind is that letters with accents (i.e. grave/acute) are made up of 2 characters: is actually '' + 'a'.

                            The other thing, from what I have read is that utf-8 does not cater for accents and there is nothing in the php to tell the database that the non-utf-8 accents are being stripped off the letters,

                            Comment


                            • #15
                              can you try running this and tell me what the output is?

                              Code:
                              <?php
                              // function declarations
                              
                              function removeSpecialChars($str) {
                                  $unwanted_array = array(    'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'A', ''=>'C', ''=>'E', ''=>'E',
                                                          ''=>'E', ''=>'E', ''=>'I', ''=>'I', ''=>'I', ''=>'I', ''=>'N', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'O', ''=>'U',
                                                          ''=>'U', ''=>'U', ''=>'U', ''=>'Y', ''=>'B', ''=>'Ss', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'a', ''=>'c',
                                                          ''=>'e', ''=>'e', ''=>'e', ''=>'e', ''=>'i', ''=>'i', ''=>'i', ''=>'i', ''=>'o', ''=>'n', ''=>'o', ''=>'o', ''=>'o', ''=>'o',
                                                          ''=>'o', ''=>'o', ''=>'u', ''=>'u', ''=>'u', ''=>'y', ''=>'b', ''=>'y' );
                              	return strtr( $str, $unwanted_array );
                              }
                              //application work
                              $results = true;
                              
                              if(strlen(trim($_POST['keyword'])) <= 3) 
                              {
                              	$results = false;
                              	$searchMsg = 'Please enter at least 3 characters';
                              }
                              
                              
                              // Find out if the user accessed the file directly
                              //if($_SERVER['REQUEST_METHOD'] == 'GET') {
                              
                                //  header('Location:Search1.php'); // redirect the user if the form was not submitted.
                                // die(); // Ignore anything after the die.
                              
                              //} elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
                              
                              // this is a much neater method of detecting post, nothing posted, send them on their way	
                              if(!isset($_POST)){
                              	header('Location:http://pintotours.net/Search/Search1.php'); // redirect the user if the form was not submitted.
                                  die(); // Ignore anything after the die. 
                              
                              }
                              
                              
                              
                              // Your database preferences
                              // We are using constants instead of variables for this
                              // You can use either or
                              define('HOST', 'localhost'); // Database host
                              define('pintotou_******', 'root'); // Database username
                              define('*****', 'root'); // Database password
                              define('pintotou_search', ''); // Database
                              
                              $mysqli = new mysqli('localhost', 'pintotou_*****', '*****', 'pintotou_search'); // Connect to the database using MySQLi_* OOP and constants
                              if($mysqli->connect_errno) {
                                  // Do not die or display any MySQL errors in this area.
                                  die('Unable to connect to the mysql server');
                              }
                              
                              $searchq = filter_var("%{$_POST['keyword']}%", FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); // Sanitize the string
                              
                              $searchq = str_replace( '-', ' ', $searchq );
                              
                              $sql = "SELECT Image, Chain, Country, City, Top as '', Medium as '', Low as '' FROM Chains WHERE Country LIKE ? OR City LIKE ?"; // Your query string
                              
                              
                              
                              $prepare = $mysqli->prepare($sql); // Prepare your query string
                              
                              $prepare->bind_param('ss', $searchq, $searchq); // Bind the placeholders to your search variables
                              // s = string | i = integer | d = double | b = blob
                              $sql = removeSpecialChars($sql);
                              
                              echo $sql;
                              die();
                              
                              
                              
                              $prepare->execute(); // Execute the prepared statement
                              
                              $prepare->store_result(); // Store the results for later checking
                              
                              // Use num_rows to check if the results return a 0 or 1. 0 meaning false and 1 meaning true
                              if($prepare->num_rows) {
                              
                                  $prepare->bind_result($image, $chain, $country, $city, $top, $medium, $low); // Append variables to the columns you specified
                              }else
                              {
                              	$results = false;
                              $searchMsg = 'There were no search results for &lsquo;'. $searchq .'&rsquo;!';
                              }
                              
                              ?>
                              Who needs a Signature?

                              Comment

                              Working...
                              X