1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

str_replace cauing weird character --> �

Discussion in 'PHP' started by timallard, Oct 7, 2009.

  1. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #21
    wow i have NO idea why this is doing this... still a weird character...

    side note: its a local server so i cant open it up to have anyone look at it :/
    SEMrush
     
    timallard, Oct 12, 2009 IP
    SEMrush
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #22
    Change your database and web encoding to UTF8.
     
    ThePHPMaster, Oct 12, 2009 IP
  3. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #23
    hmm i tried but still nothing.
    It is being inserted correctly as "Crying%Babies"
    but when it is displayed and returned it freaks out...ughh
     
    timallard, Oct 12, 2009 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #24
    inserted into the database or the search box?
     
    JAY6390, Oct 12, 2009 IP
  5. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #25
    i enter in "Crying babies" into the input and it returns "crying�bies" but gets inserted into the db as "Crying%babies" (which i want) but any time it gets returned or displayed it gives me the weird character.

    and it only happens for certain queries... "winter snow" works fine...

    It seems like something is happening on the browser end because it does not return any search results as it is looking for "crying�bies" as the keyword.

    This is my HTML meta

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">



    i am so stumped..
     
    timallard, Oct 12, 2009 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #26
    can you show your query that inserts them. Also, why are you inserting them with the %?
     
    JAY6390, Oct 12, 2009 IP
  7. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #27
    Good call on the inserting with % (i fixed that now) thanks
    Here is my query:

    $query1= "SELECT * FROM curiosities WHERE Curiosity LIKE '"."%".mysql_real_escape_string($Query)."%"."' $sort";

    echo for "Winter Snow"
    SELECT * FROM curiosities WHERE Curiosity LIKE '%winter%snow%' ORDER BY cid ASC

    echo for "crying babies"
    SELECT * FROM curiosities WHERE Curiosity LIKE '%crying�bies%' ORDER BY cid ASC
     
    timallard, Oct 12, 2009 IP
  8. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #28
    can you do
    echo ($Query);
    echo mysql_real_escap_string($Query);
    PHP:
    and paste the output of the two here
     
    JAY6390, Oct 12, 2009 IP
  9. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #29
    should be mysql_real_escape_string not escap above sorry
     
    JAY6390, Oct 12, 2009 IP
  10. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #30
    no problem ;)

    crying�bies crying�bies

    >.<
     
    timallard, Oct 12, 2009 IP
  11. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #31
    ok, can you stick the whole of your script on pastebin or something and link to it please. I'm fairly sure its not the input from the form that is messing it up
     
    JAY6390, Oct 12, 2009 IP
  12. the Player

    the Player Well-Known Member

    Messages:
    677
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    #32
    I am also experiencing this problem in my travel directory myworldtravellinks . com i searched and tried almost everything but get no solution to this special heart sign. I simply leave it as it :(
     
    the Player, Oct 12, 2009 IP
  13. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #33
    JAY - pvt message sent with the code

    @the player - if we find a solution i will let you know.
     
    timallard, Oct 12, 2009 IP
  14. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #34
    I've had a really good look at this, and can't see an error anywhere. I've tested the code, and it works as it should. I notice that in your form you have the id and name of some elements different to each other. Both should be the same, so if you have one called Query you would use
    <input type="text" id="Query" name="Query" value="default value" />
    HTML:
     
    JAY6390, Oct 12, 2009 IP
  15. szalinski

    szalinski Peon

    Messages:
    343
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #35
    It's really beyond me why you think or want it inserted into the db as "Crying%babies" - the only reason you're getting back this funny � sign is because that's what %ba is being interpreted as by your browser, look into the html source when you see that � and see what value is in there. if it's in utf8 you'll probably see the same thing. still doesn't explain why your insertion isn't just put into the db as you entered it in the first place, i.e. "Crying babies" - if you urlencode it you'd see "Crying%20babies" when inserted, but that's what mysql_real_escape_string is for - even "Crying+babies" would be better.
     
    szalinski, Oct 12, 2009 IP
  16. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #36
    use this to insert it into mysql $SearchText = str_replace(" ", "%", $SearchText); and after you are done with mysql use $SearchText = str_replace("%", " ", $SearchText); this to display the sarchtext.
     
    w47w47, Oct 13, 2009 IP
  17. califmerchant

    califmerchant Active Member

    Messages:
    112
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    63
    #37
    the diamond question mark appears when your current HTML encoding, specified in the HTML header (most likely UTF-8) encounters a symbol in a different encoding (most likely ISO-8859-1). a lot of times something will be pasted from microsoft word, it will have an ISO-8859-1 encoding.

    the solution is to convert the string into UTF-8 encoding:

    $string = mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8');
     
    califmerchant, Oct 13, 2009 IP
  18. the Player

    the Player Well-Known Member

    Messages:
    677
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    #38
    I just changed the page content type to <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> and the wired sign is no more there.

    @timallard, did you try that?
     
    the Player, Oct 16, 2009 IP