Problem with strange variable value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smatric
Forum Newbie
Posts: 3
Joined: Tue Aug 11, 2009 2:53 pm

Problem with strange variable value

Post by smatric »

Hi,

I've been struggling with this problem for some hours and I can't find a solution. I usually don't ask for help on forums but this time I just feel helpless... so I would really appreciate your suggestions.

I'm working with a CMS (MODx) and in one point I'm sending a document ID:

Code: Select all

[!anythingRating? &atrGrp=`Articles` &define=`1`!][!anythingRating? &atrGrp=`Articles` &atrId=`[*id*]`!]
and in another place I'm receiving it:

Code: Select all

$cfg['atrId'] = isset($atrId) ? $atrId : 0;
I've written a function to test it's value:

Code: Select all

function printStringCharacters($str) {
    print "string: [$str]   ";
    $c = strlen($str);
 
    print '[';
    for($i = 0; $i < $c; $i++) {
        print ord(substr($str, $i, 1)).' ';
    }
    
    print "] ";
    var_dump($str);
}
Now we come to the strange place.

When I open different documents:

Code: Select all

http://<my_domain>/147
http://<my_domain>/231
http://<my_domain>/232
This is what I get (when invoking 'printStringCharacters' function):

Code: Select all

string: [147]   [91 42 105 100 42 93 ] string(6) "147"
string: [231]   [91 42 105 100 42 93 ] string(6) "231"
string: [232]   [91 42 105 100 42 93 ] string(6) "232"
I don't understand it. Why the string (display) value is proper and the characters' codes don't change?! Is it pointing to an object??? Why then it's showing that it's a 6-character long string? Why the string is not 3-character long?.

I tried to manually encode "147" number and what I could get is:

Code: Select all

string: [147] [49 52 55 ]
string: [?1?4?7] [0 49 0 52 0 55 ] (UTF-16)
string: [147]  [49 52 55 ] (UTF-7)
string: [147]  [49 52 55 ] (EUC-JP)
string: [147]  [49 52 55 ] (SJIS)
string: [1?4?7?]  [49 0 52 0 55 0 ] (UCS-2LE)
string: [147]  [49 52 55 ] (JIS)
string: [147]  [49 52 55 ] (eucjp-win)
string: [147]  [49 52 55 ] (sjis-win)
So it's not about encoding. What is it then?

It wouldn't bother me if not the SQL query which works with '147' for example but doesn't work with $cfg['atrId'].

Thanks,

Mateusz Sobczak
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problem with strange variable value

Post by requinix »

What about if this is right at the beginning of the function?

Code: Select all

echo gettype($str);
If that says "string" then I've run out of ideas.
smatric
Forum Newbie
Posts: 3
Joined: Tue Aug 11, 2009 2:53 pm

Re: Problem with strange variable value

Post by smatric »

It does... Thank though.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problem with strange variable value

Post by requinix »

This MODx thing: is it an extension to PHP or just code you download and use?
smatric
Forum Newbie
Posts: 3
Joined: Tue Aug 11, 2009 2:53 pm

Re: Problem with strange variable value

Post by smatric »

It's not a PHP extension. MODx is a CMS developed in PHP.

See http://modxcms.com/ for details.
Post Reply