Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: mysql remove spaces and single quotes from string

  1. #1
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default mysql remove spaces and single quotes from string

    I like to remove single quotes from a mysql string but no luck so far.

    It's javascript but it has to work for phpmyadmin database and I did not know where to place this.


    Code:
        
    <script type="text/javascript">
    $(document).on("click",".item", function(e) {
    var filename = $(this).text().toLowerCase() + '.php';
    
    filename = filename.replace(/\s+/g, '').replace(''', ''); /* remove spaces and non-alpha characters from string */
    
    
    $('#uitkomst').load(filename);
    e.preventDefault();
    });
    </script>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,374
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    Replace will work without a regular expression, but you cannot use the same delimiter as the character you wish to replace. There could also be other problems, but it might be as simple as that (choosing proper delimiters, double quotes in this case):

    Code:
    filename = filename.replace(/\s+/g, '').replace("'", '');
    In any case, that much must be done.

    If you want more help, please provide a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Thank you, I did try this but it looks like there is another problem in the database I find words with strange letters like financiƫlenotasenprocedures.

    In my code I use

    Code:
    mysql_query("set names 'utf8'");
    My collation-server=utf8_general_ci

    ENGINE = InnoDB

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,374
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    That I don't know about precisely. But I do know that you have to encode everything the same all the way through the process, through generating the data, to its storage and retrieval, and to presentation. Otherwise you will have to convert or strip at certain points, perhaps losing data in the process.

    Also, I just realized, I gave you bad advice on the replace, not using a regular expression will only get rid of the first instance of the thing to be replaced, and, since you're already using a regular expression, you should be able to combine them:

    Code:
    filename = filename.replace(/\s+|'/g, '');
    If you also want to also get rid of all those odd looking characters, try:

    Code:
    filename = filename.replace(/\s+|[^0-z]/g, '')
    which will still also remove ' , and will also remove " - if you want to keep " do:

    Code:
    filename = filename.replace(/\s+|[^0-z"]/g, '')
    But a better option might be:


    Code:
    filename = filename.replace(/\W/g, '')
    which gets rid of everything that's not a word character or a number.
    Last edited by jscheuer1; 12-21-2016 at 01:28 PM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Thank you Sir but no result.

    The problem is that when I try to open a php page with

    Code:
    <script type="text/javascript">
    $(document).on("click",".item", function(e) {
    var filename = $(this).text().toLowerCase() + '.php';
    
    filename = filename.replace(/\s+/g, '').replace(''', ''); /* remove spaces and non-alpha characters from string */
    
    
    $('#uitkomst').load(filename);
    e.preventDefault();
    });
    </script>
    The page opens but no results from the database items with the same name.

  6. #6
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    432
    Thanks
    0
    Thanked 54 Times in 50 Posts

    Default

    That is no surprise as you haven't even bothered to make the basic change recommended in post #2!

  7. #7
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    I did try the codes from post #2, the first one did work but not as I hoped, the other 3 blocked my script that's why I put the first one back.

    I still think it has to do with the database itself.

    In phpmyadmin this is what I see,

    coƶrdinatorenoverleg.php should be coördinatorenoverleg.php

    financiĆ«lenotasenprocedures.php should be financiėlenotasenprocedures.php

    klantentevredenheidenquĆŖte.php should be klantentevredenheidenquźte.php

    So every word with a non alphanumeric character gives a problem.

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,374
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    What encoding is the page served in? Looks like it's ISO-8859-1 (or some variant). If it were UTF-8, then (for example):

    coƶrdinatorenoverleg.php

    would usually be:

    coördinatorenoverleg.php

    What does it look like on the page?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    I just noticed that only the file names have strange characters on the server.

    Click image for larger version. 

Name:	2016-12-24 16_42_48-www.4graphi-x.be - DirectAdmin v1.50.1.jpg 
Views:	79 
Size:	13.7 KB 
ID:	5995


    The encoding is


    Click image for larger version. 

Name:	2016-12-24 16_44_14-www.4graphi-x.be _ localhost _ graphix_effect _ items _ phpMyAdmin 4.6.3.jpg 
Views:	82 
Size:	7.7 KB 
ID:	5996



    Thank you and merry christmas.
    Last edited by Bicklo; 12-24-2016 at 03:53 PM.

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,374
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    I mean the encoding on the page, what is it served as?

    If you want more help, please put up a live demo of the problem.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. mySQL Single Quote Issue
    By jdadwilson in forum MySQL and other databases
    Replies: 1
    Last Post: 07-24-2013, 01:11 AM
  2. how to remove this string using regex
    By smansakra in forum PHP
    Replies: 16
    Last Post: 08-28-2011, 06:55 PM
  3. Remove Spaces Between Tabs (Tab Content script v2.2)
    By vlane95678 in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 03-16-2009, 11:40 PM
  4. remove html comments from string
    By IRG in forum JavaScript
    Replies: 1
    Last Post: 11-01-2008, 04:02 AM
  5. single quotes & double quotes insert into mysql
    By shyne in forum MySQL and other databases
    Replies: 3
    Last Post: 11-25-2007, 09:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •