Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Problem comparing strings

    I have a script what compares 2 strings. This is what it outputs

    "PlayballAW.pdf, 1000 A5, 2pp\r\nPlayRugFootAW.pdf, 2000 A5, 2pp (was PlayballAW.pdf, 1000 A5, 2pp PlayRugFootAW.pdf, 2000 A5, 2pp before)"

    The top line has \r\n in it however the bottom one doesn't

    If that's the only difference I'd like it to think the strings are the same. What's the best way to remove formatting like \r\n to compare the strings? I've tried using str_replace to remove them but it stills says the strings are different.
    Last edited by tomharto; 03-08-2013 at 12:18 PM.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,386
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    Show us the scripting you use to compare them. Or show us the whole script. There are different ways to compare.

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    PHP Code:

    $diffNames 
    = array('jobID' => 'ID',
        
    'ID' => 'ID',
        
    'client' => 'client',
        
    'addressLine1' => 'addressLine1',
        
    'addressLine2' => 'addressLine2',
        
    'town' => 'town',
        
    'county' => 'county',
        
    'postcode' => 'postcode',
        
    'contactName' => 'contactName',
        
    'email' => 'email',
        
    'tel' => 'tel',
        
    'jobname' => 'jobname',
        
    'quantity' => 'quantity',
        
    'size' => 'size',
        
    'paper' => 'paper',
        
    'payment' => 'payment',
        
    'delivery' => 'deliverymethod',
        
    'jobStatus' => 'jobfinished',
        
    'size2' => 'size',
        
    'finishing' => 'finishing',
        
    'extra' => 'jobspec',
        
    'datedue' => 'duedate',
        
    'amount' => 'price',
        
    'invoiceDetails' => 'invoiceDetails');

    foreach (
    $Dets as $k => $v)
    {
        if ((
    $k == 'delivery2') || ($k == 'emailHaydn'))
        {}else{
            if (
    is_string($v))
            {
                if (
    str_replace('\r\n'''$v) !== str_replace('\r\n'''$ori[$diffNames[$k]]))
                {
                    
    $diff[] = $k;
                    
    $diff2[$k]['ori'] = str_replace('\r\n'''str_replace('<br />' ''$ori[$diffNames[$k]]));
                    
    $diff2[$k]['dets'] = str_replace('\r\n'''str_replace('<br />' ''$v));
                }
            }
            else
            {
                if (
    $v !== $ori[$diffNames[$k]])
                {
                    
    $diff[] = $k;
                    
    $diff2[$k]['ori'] = $ori[$diffNames[$k]];
                    
    $diff2[$k]['dets'] = $v;
                }
            }
        }

    $Dets is a array containing everything from $_POST just ran through mysql_real_escape_string

    $ori is an array made from mysql_fetch_assoc which returns 1 row from a database

    $diffNames just contains the different input names as some inputs on the form are different from the names in the database

  • #4

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Are you looking at four character: \r\n or at two characters \r\n? If its two characters, the str_replace here won't work since it is looking at four characters: \+r+\+n since it is in single quotations.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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