Hello,

I trying to post a string, but ihave a problem

When I post the string in chrome, the string length that i post it is more than the realy string that i send, but in firefox and IE the post is working correctly, what is the reason for this ?

Thanks a lot.

Recommended Answers

All 5 Replies

Give me an example

for example, if i send this string
"כגדכ ד עכגיע כג סי
דגכעכגי גכגיי יעיעי
געכיע יעגכחגכ דדע"

*UTF-8 charset

if the length is X chars, when i post it with chrome it will post it with the same string but the length is X+2.

I suggest that there are some additional chars that i cannot see them.

Is there something to do with the string before i post it ?

How are you posting it.

This would be the normal way i'd post it

<?php
    $posting = $_POST['posting'];

    if ($_POST['submit']) {
        EXAMPLE:
        echo $posting;
    }
?>
<form action="page.php" method="POST">
    <input type="text" name="posting"/>
    <input type="submit" name="submit" value="Post"/>
</form>
Member Avatar for diafol

You may find that the encoding is different in each browser? How are you retrieving the character count? which function?

Here's some code I knocked up:

<?php
header('Content-Type: text/html; charset=utf-8'); 
if($_POST){

    $text = $_POST['text'];

    echo "MB STRLEN : " . mb_strlen($text,"UTF8") . "<br />";
    echo "STRLEN : " . strlen($text) . "<br />";
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
   </head>
   <body>
    <form method="post">
        <textarea name="text">כגדכ ד עכגיע כג סי
דגכעכגי גכגיי יעיעי
געכיע יעגכחגכ דדע</textarea>
        <input type="submit" name="submit" value="send" />
    </form>

   </body>
   </html>

It gave me the following results in Chrome, IE, FF, Opera and Safari:

MB STRLEN : 58
STRLEN : 104

So it's all pretty consistent for me.

diafol's answer, dead on, correct, specify encoding.

UTF8 is the default encoding for a growing group of browsers, with inbuilt advanced language support, chrome safari and opera spring to mind.
UTF8 support huge character sets with no more than hex80 (128) characters encoding. characters above hex7f are represented by a two byte string (80 00 to 80 7f), characters above hex80 7f are represented by a three byte string etc
since there are characters in the OP represented by shaded squares on my laptop running lynx,
(today am playing text only, the web is dead boring on lynx)
I assume that there are characters that Chrome would represent with a 2byte string, adding characters to the stringlength

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.