Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8016201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:28:33+00:00 2026-06-04T20:28:33+00:00

I’ve got a little chatbox, everything’s working, except for sending special latin chars like

  • 0

I’ve got a little chatbox, everything’s working, except for sending special latin chars like äöü.

This is the post which sends the input, as soon enter is pressed (it’s placed in the body, not in the header, couldn’t figure out how to put it in the header –> vBulletin Template):

<script type="text/javascript">
  $("#shout").keypress(function(e) {
    if(e.keyCode == 13) {
      $.ajax({
        url: "http://example.com/api.php",
        contentType: "text/html; charset=ISO-8859-1",
        data: {
          action: "shout",
          // This is what I found on the internet to
          // encode the data, but didn't help.
          message: $('<div />').text($("#shout").val()).html()
        },
        success: function() {
          $("#shout").val("");
        }
      })
    }
  });
</script>

On the server side

// Insert shout
case "shout":
if(isset($_GET['message']) && $_GET['message'] != "") {
  $mc->insertShout($userid, mktime(), $_GET['message']);
}

break;

insertShout logic

public function insertShout($userid, $date, $message, $notification = 0) {
  $sql = "INSERT INTO
  vb_chatbox_shout (userid, dateline, message, message_raw, notification)
        VALUES
          (?, ?, ?, ?, ?)";

  $stmt = $this->db->prepare($sql);

  $stmt->bindParam(1, $userid);
  $stmt->bindParam(2, $date);
  $stmt->bindParam(3, $message);
  $stmt->bindParam(4, $message);
  $stmt->bindParam(5, $notification);

  if(!$stmt->execute()) {
    var_dump($stmt->errorInfo());
  }

  return 1;
}

I’ve tried using utf-8 as charset, but no luck. Also, post didn’t help. Using this kind of ajax to pull the chatbox content works like a charm (special chars directly inserted to db with phpmyadmin are showed correctly).

The problem is not in inserting the chars to the database. When I dump the $_GET var at the first entry point, it’s already messed up, so the problem’s between jQuery and PHP.

New headers

GET /api.php?action=shout&message=%25C3%25B6%25C3%25A4%25C3%25BC HTTP/1.1
Host: example.com
Connection: keep-alive
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5
Accept: */*
Referer: http://example.com/forum/forum.php
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: skimlinks_enabled=1; bb_lastvisit=1316066700; bb_lastactivity=0; bb_userid=1;


HTTP/1.1 200 OK
Date: Mon, 28 May 2012 17:26:14 GMT
Server: Apache
X-Powered-By: PHP/5.2.9
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:28:35+00:00Added an answer on June 4, 2026 at 8:28 pm

    replace

    message: $('<div />').text($("#shout").val()).html()
    

    with

    message: encodeURIComponent($('<div />').text($("#shout").val()).html())
    

    in javascript, and then replace

    $mc->insertShout($userid, mktime(), $_GET['message']);
    

    with

    $mc->insertShout($userid, mktime(), urldecode($_GET['message']));
    

    and add

    header('Content-type: text/html; charset=utf-8');
    

    at the beginning of PHP file.

    if urldecode at php doesn’t work, try replacing it with rawurldecode().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.